Skip to content

integrate wlog using log4net

JanickGers85 edited this page Nov 1, 2016 · 7 revisions

Integrate wlog in your application using log4net

Download Wlog client libraries and include it in your poject as reference. You'll need to download the following:

  • Wlog.Clients
  • Wlog.Clients.Log4Net

These libraries uses "Newtonsoft Json.Net" library and log4net, so if your project dont use yet you'll have to add them.

After that you have the possibility to use two different appenders:

WebAppender

This appender sends single log entry to Wlog. You have to add the following to the config file of your application:

    <logger name="WebAppenderLogger">
      <level value="INFO" />
      <appender-ref ref="WebAppender" />
    </logger>

    <appender name="WebAppender" type="Wlog.Clients.Log4Net.WebAppender, Wlog.Clients.Log4Net" >
      <ApplicationKey value="{8C075ED0-45A7-495A-8E09-3A98FD6E8248}" />
      <Destination value="http://localhost:55044/api/log" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
      </layout>
    </appender>

BufferedWebAppender

This appender sends buffers log entries to Wlog; the buffer size can be setted using the parameter BufferSize of the appender. You have to add the following to the config file of your application:

    <logger name="BufferedWebAppenderLogger">
      <level value="INFO" />
      <appender-ref ref="BufferedWebAppender" />
    </logger>

    <appender name="BufferedWebAppender" type="Wlog.Clients.Log4Net.BufferedWebAppender, Wlog.Clients.Log4Net" >
      <ApplicationKey value="{8C075ED0-45A7-495A-8E09-3A98FD6E8248}" />
      <Destination value="http://localhost:55044/api/log" />
      <BufferSize value="1000"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
      </layout>
    </appender>

Logging levels and logger's name has been choosen only as an example.

Note that in this example we use only our target; it is useful to log also in a local file appender to avoid to lost logs in case of network issues. You have to add the following appender to the config file:

Param in target:

  • ApplicationKey="{8C075ED0-45A7-495A-8E09-3A98FD6E8248}" : use guid of your application; this is the guid of preconfigured sample application
  • destination="http://localhost:55044/api/log": it's the url of you serve api, change accordlyung with your server