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

  • Home
  • SEARCH
  • 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 181825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:49:54+00:00 2026-05-11T14:49:54+00:00

I am using log4net 1.2.10.0. I have extended ILog and LogManager to include a

  • 0

I am using log4net 1.2.10.0. I have extended ILog and LogManager to include a new level, ‘AUDIT’. I want to use an AdoNetAppender to log the %message to a database. I need other information logged and I tried using log4net.ThreadContext.Properties.

I get no output when I try to use a context property as a value for a SQL parameter.

<log4net>   <level>     <name value='AUDIT' />     <value value='35000' />   </level>   <appender name='AdoNetAppender.Audit' type='log4net.Appender.AdoNetAppender'>     <filter type='log4net.Filter.LevelMatchFilter'>       <levelToMatch value='AUDIT' />     </filter>     <filter type='log4net.Filter.DenyAllFilter' />     <connectionType value='System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' />     <connectionString value='data source=db1;User ID=user;Password=pass' />     <commandText value='INSERT INTO table1 VALUES(:custom_prop, :message)' />     <parameter>       <parameterName value=':custom_prop' />       <dbType value='String' />       <layout type='log4net.Layout.PatternLayout'>         <conversionPattern value='%property{custom_prop}' />       </layout>     </parameter>     <parameter>       <parameterName value=':message' />       <dbType value='String' />       <layout type='log4net.Layout.PatternLayout'>         <conversionPattern value='%message' />       </layout>     </parameter>   </appender>   <root>     <level value='ALL' />     <appender-ref ref='AdoNetAppender.Audit' />   </root> </log4net> 

The executing code is (assuming log4net has been init’ed and a logger, ‘log’, has been created).

log4net.ThreadContext.Properties['custom_prop'] = 'value'; log.Audit('a message'); 

The appender works with the AUDIT filter if I hard-code a value instead of using a SQL parameter.

... <commandText value='INSERT INTO table1 VALUES('value', :message)' /> ... 

The appender works with the context property if I filter on a built-in level, like INFO.

... <filter type='log4net.Filter.LevelMatchFilter'>   <levelToMatch value='INFO' /> </filter> ... 

A FileAppender works with the AUDIT filter and context property!

<appender name='FileAppender' type='log4net.Appender.FileAppender' >   <filter type='log4net.Filter.LevelMatchFilter'>     <levelToMatch value='AUDIT' />     </filter>   <filter type='log4net.Filter.DenyAllFilter' />   <file value='test.log' />   <layout type='log4net.Layout.PatternLayout' >     <conversionPattern value='%-5level [%property{custom_prop}] - %message%newline' />   </layout> </appender> 

Resulting in

AUDIT [value] - a message 

Using a global context property works with the AdoNetAppender and AUDIT filter. But, I need thread context resolution.

log4net.GlobalContext.Properties['custom_prop'] = 'value'; log.Audit('a message'); 

Resulting in

table1 custom_prop message =========== ======= value       a message 

So, I don’t know if it’s a problem with the AdoNetAppender or my extended classes or my configuration.

  • 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. 2026-05-11T14:49:54+00:00Added an answer on May 11, 2026 at 2:49 pm

    The problem was caused by early abortion of the foreground thread. I think log4net was running an async operation. Putting a sleep at the end of the test app fixed the problem

    ... log4net.ThreadContext.Properties['custom_prop'] = 'value'; log.Audit('a message'); ... Thread.Sleep(1000); 

    or, when in a separate thread, joining on it

    Thread t = new Thread(new ThreadStart(delegate {     log4net.ThreadContext.Properties['custom_prop'] = 'value';     log.Audit('a message');         })); t.Start(); ... t.Join(); 

    In normal operation, log4net should have enough time between the latest AUDIT call and the end of execution.

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

Sidebar

Related Questions

I am using Log4Net with the AdoNetAppender to log messages from a simple systray
I'm using log4net to log write log message to a rolling log file. Now
I have been using Log4Net for several months, and I create a new Logger
So, I have log4net configuration in log4net.config file and I don't want to include
I have a Windows form App which write to log files using log4net. The
I want to use a new version of log4net with nhibernate. The log4net version
I am using log4net and a customized AdoNetAppender to log error messages into a
I have created a simple scenario using Log4net, but it seems that my log
We have an application that logs using log4net. But we would like to delete
I'm using log4Net for my logging. I also have the following set... <log4net debug=true>

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.