step-by-step guide line for integrating Log4Net in asp.net application

i have big form where user feed data and submit. after submit a server side method call occur and from there server side method we just capture data entered by user and call 3rd part web service and provide those user data to the web service. some time web
service return error message due to send wrong data. now i want to maintain log error with entered form data and send email using  Log4Net to admin. so admin can see what data user input and what error message web service return.

i never use log4net. so first need step-by-step guide line how to incorporate in any existing web apps and later i want to know how to configure it in such way as a result when error occur then it will capture and send a automatic email to admin and save
log to db.

thanks

Please take a look at this post

Adding Log4Net to your MVC project

i have seen the url but not good because not elaborately explain each config property. so here i am asking again few question about config section for log4net.

looking for some one who can help me to understand each property usage.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <log4net>
    <appender name="DbAppender" type="log4net.Appender.ADONetAppender">
      <bufferSize value="0" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="{auto}" />
      <commandText value="INSERT INTO Log4Net ([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.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%t" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="10" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%p" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="1000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%c" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%m" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
    </appender>

    <root>
      <level value="INFO" />
      <appender-ref ref="RollingFileAppender" />
      <appender-ref ref="DbAppender" />
    </root>
  </log4net>
</configuration>

please see the above config details and answer each property. 1) why

<bufferSize value="0" />

is set to 0 ? when one should set other value to

bufferSize

property ?

2)

<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

how do i know what

PublicKeyToken

value i need to use.

3) what is the meaning of connection string auto

<connectionString value="{auto}" />

?

4)

what is the meaning of conversionPattern or

5 what is ExceptionLayout

<layout type="log4net.Layout.ExceptionLayout" />

6) what is the meaning of below xml

<root>
  <level value="INFO" />
  <appender-ref ref="RollingFileAppender" />
  <appender-ref ref="DbAppender" />
</root>

what is

RollingFileAppender

? what is

DbAppender

?

please discuss about my each point & question. thanks

Leave a Reply