-
How to implement Log4Net for Integration Manager in your .NET Application
-
Start by adding the Log4Net Nuget Package to your project (or simply reference in the log4net.dll file)
-
Add IM.Libraries.Contracts.dll and IMLogAppender.dll as a reference to your project
-
Add a service reference that points to the Log API of Integration Manager and name the service reference “logService”.
-
In the file/files where the user wants to enable logging the user has to add using directives for Log4Net. Create a new object of log4net.Logmanager. Use the object created where the user wants to have logging event.
In the example below it is basically a unit test that logs an info message.
As mentioned earlier there are five different logging levels, Debug, Info, Warn, Error and Fatal that the user are able to use. The message between the brackets will be displayed as log text as standard in the Integration Manager message view.var log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().De claringType); log.Info("First logged event with Log4Net for Integration Manager");
- Add the line: [assembly: log4net.Config.XmlConfigurator(Watch = true)] in the main class to tell make sure that Log4Net looks at the configuration file.
-
Open your web/app.config and make sure that the service address uses the correct contract. When adding the service reference it will automatically add the contract used by the service reference, but in this case it adds the wrong namespace.
Change it from logService.ILogApiService
To IM.Libraries.Contracts.ServiceContracts.ILogApiService -
The user uses a configuration file to customize the message that is being sent. This file is automatically created as “app.config” or “web.config” for web applications when the user creates the service reference.All the different parameters are assigned automatically with fitting information but if the user wants to send custom information with the different parameters it is possible to input that information using the configuration file.The user also have the possibility to choose at what level logging should be enabled by changing the value of the level element in the root category. This will also change which messages will be sent to Integration Manager.To make it easier for the user a standard configuration sections can be found in section 1.2 of this document.We recommend that the user sets an Endpoint name, this will create a new custom endpoint when sending the first message with a new endpoint name. It is also good if the user sets an Original Message Type to collect all the messages from IMLogAppender as one message type.The following parameters are available for user input:
Parameter Type OriginalMessageType
String (Recommended to be set by user)
AppInterchangeIDStr
String (Formatted as Guid )
EventNumber
Int
EndPointName
String (Recommended to be set by user)
EndPointUri
String
LogAgentID
Int
LogApiServiceURI
String
LocInterChangeIDStr
String (Formatted as Guid )
LogStatusID
Int
LogText
String
ModuleType
String
ProcessingUser
String
ProcessName
String
ProcessingMachineName
String
ProcessingModuleName
String
ProcessingModuleType
String
ServiceInstanceActivityIDStr
String (Formatted as Guid )
<configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" /> </configSections> <appSettings> <add key="IM.Log4Net.IsOneWay" value="false" /> </appSettings> <log4net> <appender name="IMAppender" type="IM.Log4NetAppender,IMLogAppender"> <!-- Custom Parameters --> <OriginalMessageType value="Unparsed Interchange" /> <LogAgentID value="101"/> <EventNumber value="0"/> <EndPointName value="Log4Net Unit Test"/> <EndPointUri value="VS.local.log4net.test"/> <LogText value =""/> <ProcessingUser value="Administrator"/> <ModuleType value="unit test"/> <ProcessName value="unit test"/> <ProcessingMachineName value="DEV"/> <ProcessingModuleType value="unit test"/> <ProcessingModuleName value="VS"/> <LogApiServiceURI value="http://localhost/IM/LogAPI/LogApiService.svc"/> <AppInterchangeIDStr value="{99106FF5-C7BB-4244-9EB7-F99040190F32}"/> <LocInterChangeIDStr value="{E4CDDF18-9925-4A79-8E9F-71BC0D4C5172}"/> <ServiceInstanceActivityIDStr value="{E4CDDF18-9925-4A79-8E9F-71BC0D4C5173}"/> </appender> <root> <level value="DEBUG"/> <appender-ref ref="IMAppender"/> </root> </log4net>