Monday, November 21, 2016

Notes on Log4Net

1. Add log4net.config to project
2. Add keys to app.config pointing to log4net config file and setting watch attribute.
Watch dictates whether log4net polls for changes in the log4net config
    <add key="log4net.Config" value="log4net.config"/>
    <add key="log4net.Config.Watch" value="True"/>
3. Add the configSsection to the app.config
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
4. Add any appenders. Set log rollover and locking model for file appenders. Each appender must have a unique name. Include a layout

      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline - %type cow" />
      </layout>

5. Add at least one appender name to the root logger. More than one appender can also be added. Note that you can filter log message types using <level value="All"/>
    <root>
      <level value="All"/>
      <appender-ref ref="ManagedColoredConsoleAppender"/>
    </root>


If logging to Mongo you want to consider using a capped collection. Capped collections are disabled by default. A capped collection allows for a FIFO buffer like behavior for self regulating log storage.

If logging to Rabbit (requires custom appender https://github.com/haf/log4net.RabbitMQ/blob/master/src/log4net.RabbitMQ/ExchangeBinding.cs) consider separate security and whether vhost should be the same as the app.

No comments:

Post a Comment