Skip to content

integrate HubLink using log4net

Daniele Fontani edited this page Apr 2, 2017 · 2 revisions

Install library

Download HubLink client libraries and include it in your poject using nuget.

Install-Package HubLink.Clients.Log4Net

This will install HubLink libs and their references.

HubLink.Clients HubLink.Clients.Log4Net

Configure log4net

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

  1. WebAppender
  2. BufferedWebAppender

Main difference between them is basically that the second one send a chunk of log instead of sending individually. The buffered version is preferred for performance issues, but may create more latency from the creation of log and the moment it is stored in the server (you need to wait fro collecting a set of logs before send...)

WebAppender

This appender sends single log entry to HubLink Server. 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="HubLink.Clients.Log4Net.WebAppender, HubLink.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 HubLink; 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="HubLink.Clients.Log4Net.BufferedWebAppender, HubLink.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
Clone this wiki locally