C# Tutorial – Logging database with log4net | FoxLearn


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



  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}" />


    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" ?>
    <section name="log4net" type="log4net.Config.Log4NetConfigrationSectionHandler,log4net"/>
    <level value="All"></level>
    <appender-ref ref="AdoNetAppender_Oracle"></appender-ref>
    <appender name="AdoNetAppender_Oracle" type="log4net.Appender.AdoNetAppender">
    <connectionType value="Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    <commandText value="INSERT INTO LOGGER(DETAIL,LOG_AUDIT) VALUES ('as24das','asds')" />
    <bufferSize value="1" />
    <parameterName value=":log_date" />
    <dbType value="DateTime" />
    <layout type="log4net.Layout.RawTimeStampLayout" />
    <parameterName value=":thread" />
    <dbType value="String" />
    <size value="255" />
    <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%thread" />
    <parameterName value=":log_level" />
    <dbType value="String" />
    <size value="50" />
    <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%level" />
    <parameterName value=":logger" />
    <dbType value="String" />
    <size value="255" />
    <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%logger" />
    <parameterName value=":message" />
    <dbType value="String" />
    <size value="4000" />
    <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%message" />

    Thanks for helps 🙂


Please enter your comment!
Please enter your name here