Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 891897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:57:48+00:00 2026-05-15T13:57:48+00:00

I’m using log4net and I configured my XML file to log into database with

  • 0

I’m using log4net and I configured my XML file to log into database with AdoNetAppender and everything seems to work properly when I create the application and configure everything. And I can successfully log to the database. But when I change the message in my code then it stops logging to the database.

Here is my configuration:

<appender name="ADONetAppender" 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="Server=USER-PC;Integrated Security=SSPI;Initial Catalog=mydb;Trusted_Connection=true;"/>
  <commandText value="INSERT INTO Log1 ([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">
      <converter>
        <name value="hex_thread" />
        <type value="MyWebApplication.HexPatternConverter" />
      </converter>
      <conversionPattern value="%hex_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>

I found it online and did a little modification to suit my application. I’m thinking it could be because we insert into the table Log1 before getting the parameters MAYBE I really don’t know because I am new to XML world and I know very little about it.

If my code is

 private static readonly ILog dblog = LogManager.GetLogger("ADONetAppender");
 dblog.Info("logging to db");

it works the first time, and then I change the message like this

dblog.Info("I AM LOGGING TO DB"); 
dblog.Info("me again");

it will not work at all, my file appenders are all right they can take the message change but my AdoNetAppender refuses this. Why is this happening?

Edited to add:

My functions are very simple I have this class to do the logging:

using System; 
using System.Collections.Generic; 
using System.Linq; using System.Web;using log4net; 
using log4net.Config; using log4net.Core;
using log4net.Layout; using System.Text; 
using System.IO; 
using log4net.Layout.Pattern; 

namespace myWebApplication 
{

public sealed class HexPatternConverter : PatternLayoutConverter
{
    override protected void Convert(TextWriter writer, LoggingEvent loggingEvent)
    {
        long id;
        if (long.TryParse(loggingEvent.ThreadName, out id))
        {
            writer.Write(id.ToString("X"));
        }
        else
        {
            writer.Write(loggingEvent.ThreadName);
        }
    }
}

public class myClass
{
    private static readonly ILog secondlog = LogManager.GetLogger("methodB");
    private static readonly ILog thirdlog = LogManager.GetLogger("methodC");
    private static readonly ILog fourthlog = LogManager.GetLogger("methodD");
    private static readonly ILog fifthlog = LogManager.GetLogger("ADONetAppender");

    public static int methodA()
    {
        int a = 0;
        return a;
    }
    public static void methodB()
    {
        methodA();
        secondlog.Info("inside method B");
    }
    public static void methodC()
    {
        methodB();
        thirdlog.Info("inside method C");
    }

    public static void methodD()
    {
        methodC();
        fourthlog.Info("inside D");
        fifthlog.Info("this is db log");
        fifthlog.Info("this is me logging to the db");
    }
}

}

The file logs are okay whenever I make changes but my DB log isn’t writing to the database, because when I try to retrieve the data in my table there are no changes. I am not sure what I am doing wrong.

My Logger Configuration

<logger name="ADONetAppender">
<appender-ref ref="ADONetAppender"/>
</logger>
<logger name="methodB">
  <appender-ref ref="methodB"/>
</logger>
<logger name="methodC">
  <appender-ref ref="methodC"/>
</logger>
<logger name="methodD">
  <appender-ref ref="methodD"/>
</logger>
<root>     
</root>

The last three are RollingFileAppenders and they work perfectly wether I change the message or I add a few other messages. It’s the DB that’s giving me headache when I change the message or I add a few more messages to log.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:57:49+00:00Added an answer on May 15, 2026 at 1:57 pm

    OOH finally, its worked well… There is some code that I included in my global.asax that shouldnt be there i believe. I just tried revoming the code and it worked well. Now its instantly writing no matter how many changes i make.

    Here is the code i have no idea what it does but i just found it online. It wasnt needed in my case

     log4net.Repository.Hierarchy.Hierarchy hier = log4net.LogManager.GetRepository() as log4net.Repository.Hierarchy.Hierarchy;
    
            if (hier != null)
            {
                //get ADONetAppender
                log4net.Appender.AdoNetAppender adoAppender =
                  (log4net.Appender.AdoNetAppender)hier.GetLogger("ADONetAppender",
                    hier.LoggerFactory).GetAppender("ADONetAppender");
                if (adoAppender != null)
                {
                    adoAppender.ConnectionString =
                      System.Configuration.ConfigurationSettings.AppSettings["MyConnectionString"];
                    adoAppender.ActivateOptions(); //refresh settings of appender
                }
    
            }
    

    And after i removed it Problem solved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.