C# Tutorial – Logging database with log4net | FoxLearn

15
29



How to use log4net (logging database, log4net configuration, log4net levels, log4net dll, log4net appender, log4net example) in C#

Apache log4net – Apache log4net: Examples
log4net tutorial– Great library for logging
The log4net Tutorial: Logging in C# (hands-on from beginner to advanced)
How to use log4net
How to do Logging in C# with log4net
C# Logging Framework Log4Net
c# – Correct way of using log4net
Logging with Log4Net in C#
Using Log4Net in C#
Log4Net First Steps
log4Net Tutorial: Basic startup
Create log file in Dot Net using C#
Write error log in C#
Exception Error Handling Log
log4net c#
c# log4net

Nguồn:https://wijstaanvooronzegrondrechten.org/

15 COMMENTS

  1. Hello Lucy , i want to add a new column and log the users ip number ,
    so i added these parameters ;
    <parameterName value="@addr" />

    <dbType value="String" />

    <size value="50" />

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

    <conversionPattern value="%property{addr}" />

    </parameter>

    and also i already add a new column to database and set its value at query;
    <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception],[IP]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception,@addr)" />

    then i try this at login form ;
    log4net.LogicalThreadContext.Properties["addr"] = label4.Text;

    log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    * in my case the text of label is bound to getIP method*

    but somehow the new added column logs the same value of %message , not the new added parameter..

    Any suggestion or correction? Its possible that i have a silly mistake here , but im totally beginner. Thank you for understandings of everyone.

  2. Thank you so much.It help me alot.But i have a problem from oracle side .I did not get the right result when I applied it for the oracle version.I use oracle appender for this.It isnt work correctly.

    Here is my config file…

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigrationSectionHandler,log4net"/>
    </configSections>
    <log4net>
    <root>
    <level value="All"></level>
    <appender-ref ref="AdoNetAppender_Oracle"></appender-ref>
    </root>
    <appender name="AdoNetAppender_Oracle" type="log4net.Appender.AdoNetAppender">
    <connectionType value="Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess, Version=4.113.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    <connectionString value="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MYHOST)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MYDBNAME)));User Id=MYUSERID;Password=MYPASSWORD;" />
    <commandText value="INSERT INTO LOGGER(DETAIL,LOG_AUDIT) VALUES ('as24das','asds')" />
    <bufferSize value="1" />
    <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="%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>
    </appender>
    </log4net>
    </configuration>

    Thanks for helps 🙂

LEAVE A REPLY

Please enter your comment!
Please enter your name here