0

Possible Duplicate:
log4net file names based on GlobalContext properties

This is really starting to bother me. I'm just simply trying to add a property variable to a log4Net filename. What am I doing wrong?

Here's the config:

 <appender name="logger1" type="log4net.Appender.FileAppender">
    <file type="log4net.Util.PatternString" value="C:\temp\file_%property{foo}.log" />
    <appendToFile value="true" />         
    <Layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%newline%date --- %message%newline" />
    </Layout>    
 </appender>

And here's the code:

string foo= "bar";
log4net.GlobalContext.Properties["foo"] = foo;
_logger.ErrorFormat("test");

And the resulting log name is file-(null).log

Anyone see anything that I'm missing here? Because otherwise it seems to me to be a bug.

Rafael Tavares
  • 3,489
  • 4
  • 25
  • 44
matt_dev
  • 5,086
  • 4
  • 31
  • 43

1 Answers1

3

Answer here.

You have to set the property before you create the logger.

Community
  • 1
  • 1
Chris McCall
  • 10,181
  • 8
  • 48
  • 80