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 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=",300,700">,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:
Sent from the Log4net - Users mailing list archive at

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:
Sent from the Log4net - Users mailing list archive at

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:
Sent from the Log4net - Users mailing list archive at

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. 


Joseph L. Casale | 6 Mar 22:01 2015

Custom appender instantiation

I have a custom appender that uses parameters from the App.config file, however
I need to call an internal method after instantiation once the fields have been populated.

I see PreAppendCheck
Gert Kello | 5 Mar 13:01 2015

Debug info file for log4net release


Is it possible to download the log4net.pdb file for So that debugging log4net would be possible without making custom build.

Is there some reason why it is not included in zip? Would You consider adding it to coming releases?


Gert Kello | 4 Mar 09:27 2015

AppenderSkeletion lock in DoAppend


I'm trying to create a database appender which high throughput... I looked at code in AppenderSekeletion.DoAppend() method and saw following comment:

    public void DoAppend(LoggingEvent loggingEvent)
      // This lock is absolutely critical for correct formatting
      // of the message in a multi-threaded environment.  Without
      // this, the message may be broken up into elements from
      // multiple thread contexts (like get the wrong thread ID).

      lock (this)

I would like to remove this lock from my code but there's a couple of issues I do not understand:
1. As I do not know the internals of log4net well enough I do not understand why lock is important for message formatting? Is it because the Layout.Format is not supposed to be thread safe? Or is it because the same instance of m_renderWriter could be used by multiple threads (well, usage of m_renderWriter is protected by another lock, added later. But AFAIK the RenderLoggingEvent(LoggingEvent loggingEvent) is still not 100% thread safe)
2. The comment does not mention that lock is crucial for m_recursiveGuard to work correctly. That's my main complaint: I almost overlooked the issue of potentially skipped logging events.
3. What about implementations of IFilter.Decide? Are those (supposed to be) thread safe?

Thiemo.Kellner | 26 Feb 13:36 2015

64bit problem?

Hi all


I am at my wits’ end. We developped PowerShell script which uses log4net. I can run the script successfully from a batch file on my laptop but on the server I get


Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem'

provider failed.

I:\WA_ANALYSE\AAA_INFA_CORE\Scripts\metadata_join_params-thiemo.ps1 :

Exception calling "LoadFile" with "1" argument(s): "The parameter is

incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

At line:1 char:1

+ I:\WA_ANALYSE\AAA_INFA_CORE\Scripts\metadata_join_params-thiemo.ps1

-stat_activi ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorExcep


    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio




I found which points to a possible problem with mixing 32 dlls in 64 bit PowerShell. As my laptop is 32 and the server 64 bit, I was wondering if this might cause the problem. At least I could pin the line of code where the exception gets thrown: [void][Reflection.Assembly]::LoadFile($log4netDllPathString)


Has anyone an idea?


Liebe Grüsse/Cordialement/Cordialità


Thiemo Kellner



Office fédéral de la statistique
Espace de l'Europe 10
2010 Neuchâtel / Suisse


Tel     +41 32 71 36516


Christopher Landry | 12 Feb 21:00 2015

Dynamically change log levels confined to ThreadContext

I have a web app, and I’m trying to allow users to set the logging level via a query parameter. Got this working pretty easily.


The issue is that it doesn’t just change the logging level for that request, it’s changed for all requests that come in during the life cycle of that request – since I’m setting it back to the default level when the request is resolved.


I have tried adding the following in my appender, but it’s not working as I hoped.


<evaluator type=”log4net.spi.LevelEvaluator”>


           <layout type=”log4net.Layout.RawPropertyLayout”>

                <key value=”LogLevel” />




And set a ThreadContext property called LogLevel to the appropriate level, but that doesn’t seem to work either.


Any thoughts? Have I missed something obvious?