Application logs play an important role in the software development process. Application logs assist the software developers in the diagnosis of issues that customers are experiencing with the product. Application logs are files that contain information about events that occurred during the execution of the software application. These events are logged by the application and written to Application Logs. The Application logs can be emitted and stored in different storage medium – consoles, files, databases, etc. The events that are emitted could be informational, warning, error, or other types of messages that the software team is interested in.
The MIP RestAPI service also emits the application logs, and through a configuration file the logging can be adjusted to fit the needs of different operating environments. The RestAPI service’s logging system is based on the log4net framework.
The MIP RestAPI service code contains the logging instructions, but it does not dictate where and how that log information will be stored and processed. Instead of hardcoding the application log storage choices, the system provides the control and flexibility for the user to control the amount and the type of logging that they are interested in. By editing the log configuration file (log4net.config), the MIP RestAPI Service can be customized to store the logs in different storage mediums.
The log4net logging system provides many options to customize the log outputs. The two primary components that you need to be familiar with are Appenders and PatternLayout. Appender is a component that is used to determine the target destination the log messages will go to when the logging events are triggered. You can configure it to have multiple appenders with different levels of logging. The PatternLayout component allows you to customize the format of the log event.
The logging configuration file ( log4net.config) file can be found in the following folder: c:\Program Files
As of version 20.3.0.0, the default log file configuration that ships with the product stores the application logs in
files in the following folder: c:\program files
The MIP RestAPI service consists of two components. In the default configuration, both of those components emit the information to the same log file. The following log file configuration allows you to emit the log files into separate log files for each component. The log file names also carry the date and the process id of the process that the code was running in. This would allow you to provide the MIP product team the appropriate logs for the issue that you might be experiencing. Since the logs carry timestamps, you can provide the log files associated with that time frame.
If you make changes to the log4net.config file, please first make a backup copy of the original file so that you can restore the file if you want to revert to the default style. Once you have created a backup of the file, you can copy the below configuration into the log4net.config file and restart the Public API Windows service. The below configuration file creates a log file that would tag the logs with additional metadata and logs in a structured format.
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name= "RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type= "log4net.Util.PatternString" value="%property{LogsDirectory}/%property{LogComponentName}/%property{log4net:HostName}_%processid_%utcdate{yyyy-MM-dd}_%property{LogFileName}.log" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<converter>
<name value="processid" />
<type value="Abila.MIP.Advance.Helpers.Logger.Converters.ProcessIDPatternLayoutConverter, Abila.MIP.Advance.Helpers.Logger" />
</converter>
<converter>
<name value="traceid" />
<type value="Abila.MIP.Advance.Helpers.Logger.Converters.TraceIDPatternLayoutConverter, Abila.MIP.Advance.Helpers.Logger" />
</converter>
<conversionPattern value="{"Machine":"%property{log4net:HostName}", "PID":"%processid", "TraceID":"%traceid", "TS":"%date", "Level":"%level", "TID":"%thread", "Class":"%logger", "Method":"%M", "Message":"%message", "Exception":"%exception"},%newline" />
</layout>
</appender>
<appender name="BufferingForwardingAppender" type="log4net.Appender.BufferingForwardingAppender">
<bufferSize value="15" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="WARN" />
</evaluator>
<appender-ref ref="RollingFileAppender" />
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="BufferingForwardingAppender" />
</root>
</log4net>