Ílson Bolzan | 26 Aug 19:18 2015

Problems with ThreadContext and TransactionScope

Has anyone tried to stack contexts and use Transaction scope at the same time?

I'm trying something like this:
using (log4net.ThreadContext.Stacks["contextLog"].Push("Saving Data")) { log.Info("Starting transaction"); using (var ts = new TransactionScope(TransactionScopeOption.Required)) { log.Info("Inside Transaction"); } }
and I'm getting that result:

2015/42/26 13:42:10,841 INFO  [Saving Data] Starting transaction
2015/42/26 13:42:10,870 INFO  [(null)] Inside Transaction

I was expecting it to have [Saving Data] instead of [(null)]  on the second line.

It appears to loose access to the log4net ThreadContext Stack as soon as it enters a transaction.

Do you know how to avoid this?

Thank you so much.

Jeremiah Gowdy | 18 Aug 19:21 2015

Log4net 1.2.14

My colleague Thomas Clegg and I are proposing to do a release of log4net numbered 1.2.14.  This release would
be the existing 1.2.13 release, plus the two patches for LOG4NET-455 and LOG4NET-462.  According to our
testing, this fixes log4net’s thread context for async/await usage.  By doing a bump of 1.2.13, we avoid
the large amount of unreleased changes pending in log4net 1.3.0.

I understand the two developers of log4net are not very available to assist with this release.  Once we’ve
prepared a diff for this release how do we proceed?
Ílson Bolzan | 17 Aug 22:54 2015

Log4net New Releases


I was just wondering.
Given that there are commits from 8 days ago on the source repository.
Does anyone know hy the last stable release is from 2013?

Ílson Bolzan


Francois Botha | 7 Aug 14:00 2015

Log4Net Logging of two different levels to two different appenders for the same logger


Please refer to the question and answer in http://stackoverflow.com/a/21188397/179494

I have a similar config (see below), but at the moment DEBUG statements (and above) also print in the console. My understanding is that with this config, only ERROR and above should print in the console, but all levels should print in the rolling file. What am I doing wrong?

My config:

  <log4net debug="false">
    <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="logs\log.txt" />
      <param name="AppendToFile" value="false" />
      <param name="RollingStyle" value="Date" />
      <param name="DatePattern" value="yyyy.MM.dd" />
      <param name="StaticLogFileName" value="true" />
      <layout type="log4net.Layout.PatternLayout,log4net">
      <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />

    <appender name="console" type="log4net.Appender.ColoredConsoleAppender, log4net">
        <level value="FATAL" />
        <foreColor value="Yellow, HighIntensity" />
        <backColor value="Purple, HighIntensity" />
        <level value="ERROR" />
        <foreColor value="White" />
        <backColor value="Red" />
        <level value="WARN" />
        <foreColor value="Yellow" />
        <level value="INFO" />
        <backColor value="Blue" />
        <foreColor value="White" />
        <level value="DEBUG" />
        <foreColor value="Green" />
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%c %-5p %m%n" />
      <level value="DEBUG" />
      <appender-ref ref="console">
        <threshold value="ERROR" />
      <appender-ref ref="rollingFile" />

Francois Botha
mabra | 5 Aug 17:49 2015

RFC: Property "t/thread"

Hi !


For future changes, it would be reasonable good to add

"T/Thread" to the patterns class, which explicitely

output the thread-id as a number. Its a pain with the

threadpool threads, which are all named "Thread Pool Thread"

(or something like this) in Asp.Net.


Regard the spelling "T" or "Thread".


To always apply a context method for this, isn't

too good ...


Thanks anyway and

best regards,




Nicholas Duane | 9 Jul 04:29 2015

setting or overriding log levels via configuration?


Is there a way to set custom log levels via configuration?

Is there a way to change existing log levels via configuration?

At the end of this post http://stackoverflow.com/questions/538095/how-do-i-filter-on-a-custom-level-in-log4net I see someone had said:

"You will need to add
<level> <name value="AUDIT" /> <value value="35000" /> </level> in your log4net config section."

which lead me to believe specifying custom log levels in configuration is possible.  However after searching for a while I have seen no other reference to something similar.


Michel Émond | 8 Jun 15:43 2015

Rolling log file is overwritten when application is restarted


This is the first time I contribute to an open source project, your assistance will be much appreciated.
I read your FAQ and I believe I'm doing things in the right manner. Please let me know otherwise.

While using version 1.2.13, I'm experiencing the issue described in this bug:

In short, my app is running, rolling style is set to Composite, log files are piling up in the folder, all is good. Then I reset IIS, and restart my app. I would expect the rolling to continue on or after the last file. But instead, the rolling restarts at index 1 and overwrites the existing files.

The original bug fix addresses the issue in the InitializeFromOneFile() method.
However, the GetWildcardPatternForFile() method also needs the baseFileName to be adjusted with the datePattern so the proper files are searched.
I placed a file path fix in the DetermineCurSizeRollBackups() method, so it's then passed down to the two other methods and everyone gets happy.

Here's a calling stack sample:
|  +--GetWildcardPatternForFile()

You'll find attached to this email:
- the part of my web.config file that relates to log4net
- a patch containing my fix

Please let me know how good this fix is, and if it fits your quality standards.
Once we're settled, I could work on the unit tests, or let you deal with it at your convenience.


<at> import url(<a class="moz-txt-link-freetext" href="http://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700">http://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700); a, a:link, a:visited { color:#000000; }

Michel Émond
Programmer Analyst

T  1-514-272-0979 #240
T  1-800-972-0979 #240

Attachment (config.xml): text/xml, 1603 bytes
--- log4net-1.2.13\src\Appender\RollingFileAppender.cs	Sun Nov 17 14:44:38 2013 UTC
+++ log4net-1.2.13-fix\src\Appender\RollingFileAppender.cs	Tue May 12 17:53:22 2015 UTC
 <at>  <at>  -718,6 +718,10  <at>  <at> 
 				fullPath = System.IO.Path.GetFullPath(m_baseFileName);
+				if (m_rollDate && !m_staticLogFileName)
+				{
+					fullPath = CombinePath(fullPath, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo));
+				}
 				fileName = System.IO.Path.GetFileName(fullPath);
 <at>  <at>  -901,19 +905,6  <at>  <at> 
-			// Only look for files in the current roll point
-			if (m_rollDate && !m_staticLogFileName)
-			{
-				string date = m_dateTime.Now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo);
-				string prefix = m_preserveLogFileNameExtension ?
Path.GetFileNameWithoutExtension(baseFile) + date : baseFile + date;
-				string suffix = m_preserveLogFileNameExtension ? Path.GetExtension(baseFile) : "";
-				if (!curFileName.StartsWith(prefix) || !curFileName.EndsWith(suffix))
-				{
-					LogLog.Debug(declaringType, "Ignoring file ["+curFileName+"] because it is from a different
date period");
-					return;
-				}
-			}
 				// Bump the counter up to the highest count seen so far
karlkras | 9 Apr 19:17 2015

Can't get RollingFileAppender to work...

Hello again. So I'm trying to configure a RollingFileAppender logger to work
against a custom level. However, when I call the custom level no file with
content is created/produced.
The xml configuration looks like this:

<?xml version="1.0" encoding="utf-8"?>
		<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
requirePermission="false" />
	<log4net debug="True">
			<name value="AUDIT" />
			<value value="80000" />
			<appender-ref ref="LogglyLogger" >
				<threshold value="DEBUG" />
		<logger name="EventLogger" additivity="False">
			<level value="ERROR"/>
		<logger name="RollingFile" additivity="False">
			<level value="AUDIT"/>
		<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
			<file value="c:\logs\connector\Connector.log" />
			<appendToFile value="true" />
			<datePattern value="yyyyMMdd" />
			<rollingStyle value="Date" />
			<maxSizeRollBackups value="30"/>
			<staticLogFileName value="true" />
			<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
			<layout type="log4net.Layout.PatternLayout">
				<conversionPattern value="%-5p %d [%thread] %5rms %-22.22c{1} %-18.18M -
%m%n" />


the C# code looks like this:

public class MyLogger
		static readonly log4net.Core.Level auditLevel = new
log4net.Core.Level(80000, "Audit");
                private static ILog _logger;

                public void MyLogger()
			string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
			FileInfo finfo = new FileInfo(logFilePath);
			log4net.Core.Level auditLevel = new log4net.Core.Level(80000, "Audit");
			_logger = LogManager.GetLogger(typeof(WAConnectorLogger));

		public void Audit(string message)
				auditLevel, message, null);

but when I call this method, no log is produced. Any ideas what I'm doing
wrong here?
It all appears to proceed without error so I'm assuming something in my
configuration isn't quite right.
Other appenders are working as hoped, so there's no problem loading the
log4net xml file.


View this message in context: http://apache-logging.6191.n7.nabble.com/Can-t-get-RollingFileAppender-to-work-tp54533.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

karlkras | 8 Apr 01:13 2015

How to use a custom level in logger interface...

So I've found a sample that states to add a custom level to the log4net xml
configuration as such:
	        <name value="AUDIT" />
		<value value="80000" />

and I'm guessing I can define my logger to use it like this:

		<logger name="RollingFile" additivity="False">
			<level value="AUDIT"/>

in in the C# code, how do I specify to call the logger to call the logger
with the "AUDIT" level? e.g., for an Error level message I perform an
log4net.ILog.Error(...) call.

what do I do for the custom level since this support isn't built in, i.e.,
how/where do I inject the handlers for interact with the log4net process?


View this message in context: http://apache-logging.6191.n7.nabble.com/How-to-use-a-custom-level-in-logger-interface-tp54520.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

DeveloperM | 7 Apr 15:44 2015

Logging works in VS but not when deployed

(Apologizing for cross-posting...)

I am working in a Dynamics CRM 2011on-premises C# .Net environment. This is
the first time I have used log4net so bear with me, please...

My app.config entry for log4net is:
<appender name="RollingFileAppender"
  <file value="EDI File Generator Log.txt" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="20MB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %level %logger -
%message%newline" />
  <level value="INFO"/>
  <appender-ref ref="RollingFileAppender"/>


In the program I have coded:
private static readonly ILog log =

And throughout the program there are several places I call a method which

When I execute the code from VS 2010, the program runs and messages are
logged to the log file. When I deployed the program to my own machine, the
program runs but no log entries are written.

View this message in context: http://apache-logging.6191.n7.nabble.com/Logging-works-in-VS-but-not-when-deployed-tp54506.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Nicholas Dudas | 27 Mar 19:51 2015

Fwd: FileAppender ObjectDisposedException

I may have found a small bug in the file appender where the manual reset event is not cleaned up correctly during shutdown.