log4Net logging

I struggled a bit with understanding this tool

These articles helped a ton:

The basics

http://www.codeproject.com/Articles/140911/log4net-Tutorial

More advance

http://www.codeproject.com/Articles/406634/Creating-a-custom-log-net-appender

Then custom table example:

 

<appender name=”ADONetAppender_SqlServer” type=”log4net.Appender.AdoNetAppender”>
<bufferSize value=”1″ />
<connectionType value=”System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ />
<connectionString value=”Data Source=Jcdc-d-sql-001\dev;Database=log4Net;User Id=int_serv;Password=Int@2015!;” />
<filter type=”log4net.Filter.LevelRangeFilter”>
<levelMin value=”FATAL” />
<levelMax value=”FATAL” />
</filter>
<!–<connectionString value=”data source=JCDC-D-SQL-001\DEV;initial catalog=log4net;integrated security=true;persist security info=True;User ID=jcdev\lafrance.warren” />–>
<commandText value=”INSERT INTO AppLog ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)” />
<parameter>
<parameterName value=”@log_date” />
<dbType value=”DateTime” />
<!–
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%date{yyyy’-‘MM’-‘dd HH’:’mm’:’ss’.’fff}” />
</layout>
–>
<layout type=”log4net.Layout.RawTimeStampLayout” />
</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=”2000″ />
<layout type=”log4net.Layout.ExceptionLayout” />
</parameter>
</appender>
<!–Configure the AdoNetAppender to connect to MS SQL Server –>
<appender name=”InfoAppender_SqlServer” type=”log4net.Appender.AdoNetAppender”>
<level value=”INFO” />

<filter type=”log4net.Filter.StringMatchFilter”>
<stringToMatch value=”Sending Message” />
</filter>
<filter type=”log4net.Filter.LevelRangeFilter”>
<levelMin value=”INFO” />
<levelMax value=”INFO” />
</filter>
<bufferSize value=”1″ />
<connectionType value=”System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ />
<connectionString value=”Data Source=Jcdc-d-sql-001\dev;Database=log4Net;User Id=int_serv;Password=Int@2015!;” />
<commandText value=”INSERT INTO [dbo].[EmailLog] ([Date],[Thread],[Level],[Logger],[Message],[Exception],[StartDate],[EndDate],[DeliveryFrequency],[Address] ,[Parms] ,[Body],[sirsLogNumber], [sirsIncidentNumber]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @StartDate,@EndDate,@DeliveryFrequency,@Address,@Parms,@Body, @sirsLogNumber, @sirsIncidentNumber)” />

<parameter>
<parameterName value=”@log_date” />
<dbType value=”DateTime” />
<!–
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%date{yyyy’-‘MM’-‘dd HH’:’mm’:’ss’.’fff}” />
</layout>
–>
<layout type=”log4net.Layout.RawTimeStampLayout” />
</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=”2000″ />
<layout type=”log4net.Layout.ExceptionLayout” />
</parameter>

<parameter>
<parameterName value=”@DeliveryFrequency” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{DeliveryFrequency}” />
</layout>
</parameter>

<parameter>
<parameterName value=”@StartDate” />
<dbType value=”DateTime” />
<layout type=”log4net.Layout.RawTimeStampLayout”>
<conversionPattern value=”%property{StartDate}” />
</layout>
</parameter>
<parameter>
<parameterName value=”@EndDate” />
<dbType value=”DateTime” />
<layout type=”log4net.Layout.RawTimeStampLayout”>
<conversionPattern value=”%property{EndDate}” />
</layout>
</parameter>
<!–@sirsLogNumber–>
<parameter>
<parameterName value=”@sirsLogNumber” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{sirsLogNumber}” />
</layout>
</parameter>
<!–@sirsIncidentNumber–>
<parameter>
<parameterName value=”@sirsIncidentNumber” />
<dbType value=”String” />
<size value=”255″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{sirsIncidentNumber}” />
</layout>
</parameter>
<!–@address–>
<parameter>
<parameterName value=”@Address” />
<dbType value=”String” />
<size value=”-1″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{Address}” />
</layout>
</parameter>
<!–@parms–>
<parameter>
<parameterName value=”@Parms” />
<dbType value=”String” />
<size value=”-1″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{Parms}” />
</layout>
</parameter>
<!–@body–>
<parameter>
<parameterName value=”@Body” />
<dbType value=”String” />
<size value=”-1″ />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%property{Body}” />
</layout>
</parameter>
</appender>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s