views:

597

answers:

1

Hey folks...

This is really starting to bother me. I'm just simple trying to add a property variable to a log4Net filename. Can anobdy see anything I'm 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?

Thanks in advanvce, -Matt

+2  A: 

Answer here.

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

Chris McCall
Ah...thanks, that woould be my problem.
matt_dev