PSC.Log4net.Async

PSC.Log4net.Async componentThis library provides asynchronous Log4Net logging. Application performance is improved by performing message appending I/O operations on one or more background threads.

Forwarding appenders augment or otherwise alter the behavior of other appenders. In this case logging operations are buffered or queued until the background thread is available to forward log messages to another appender or appenders. This allows the thread that is creating log messages to continue rather than waiting on I/O operations. 

Multiple forwarding appenders may be configured, each having its own set of appenders, dedicated message queue, and background appending thread. This enables parallel appending while maintaining message sequence.

Change you log4net.config as following:

<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="false">
  <appender name="rollingFile" type="log4net.Appender.RollingFileAppender">
    <!--<file type="log4net.Util.PatternString,log4net" value="Logs\myApp.log" />-->
    <file type="log4net.Util.PatternString">
      <conversionPattern value="Logs/log-%date{yyyy.MM.dd.HH.mm.ss}.log" />
    </file>
    <appendToFile value="true" />
    <threshold value="ALL" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="10MB" />
    <staticLogFileName value="true" />
    <layout type="log4net.Layout.PatternLayout,log4net">
      <param name="ConversionPattern" value="%utcdate|%-5level|%logger|%thread| %message %exception%n" />
    </layout>
  </appender>

  <appender name="console" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%d|%-5level|%logger| %message %exception%n" />
    </layout>
    <threshold value="ALL" />
  </appender>

  <appender name="adoNet" type="log4net.Appender.AdoNetAppender">
    <connectionType value="System.Data.SqlClient.SqlConnection, System.Data,Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <connectionString value="MyConnectionString" />
    <commandText value="INSERT INTO Log4Net([Date], [Thread], [Level], [Logger], [Message], [Exception], [Application]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @application)" />
    <ReconnectOnError value="true" />
    <threshold value="ALL" />
    <parameter>
      <parameterName value="@log_date" />
      <dbType value="DateTime" />
      <layout type="log4net.Layout.RawUtcTimeStampLayout" />
    </parameter>
    <parameter>
      <parameterName value="@thread" />
      <dbType value="String" />
      <size value="255" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%thread" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@log_level" />
      <dbType value="String" />
      <size value="50" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%level" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@logger" />
      <dbType value="String" />
      <size value="255" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%logger" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@message" />
      <dbType value="String" />
      <size value="4000" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%message" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@exception" />
      <dbType value="String" />
      <size value="4000" />
      <layout type="log4net.Layout.ExceptionLayout" />
    </parameter>
    <parameter>
      <parameterName value="@application" />
      <dbType value="String" />
      <size value="200" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="MyApplicationName" />
      </layout>
    </parameter>
  </appender>

  <appender name="asyncForwarder" type="PSC.Log4net.Async.AsyncForwardingAppender,PSC.Log4net.Async">
    <appender-ref ref="console" />
    <appender-ref ref="rollingFile" />
  </appender>

  <appender name="adoAsyncForwarder" type="PSC.Log4net.Async.AsyncForwardingAppender,PSC.Log4net.Async">
    <appender-ref ref="adoNet" />
  </appender>

  <root>
    <priority value="ALL" />
    <appender-ref ref="asyncForwarder" />
    <appender-ref ref="adoAsyncForwarder" />
  </root>

</log4net>

Download this component from NuGet

Download a log4net.config for your application log4net.config.xml (3.68 kb) log4net.zip (1.78 kb)

Advertsing

125X125_06

Planet Xamarin

Planet Xamarin

Calendar

<<  September 2017  >>
MonTueWedThuFriSatSun
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

View posts in large calendar

Month List