Log4Net dynamic file name not working

Possible duplicate:
log4net file names based on GlobalContext properties

It really starts to bother me. I'm just trying to add a property variable to the log4Net file name. Can anobdy see something that I am doing wrong?

Here 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 is the code ...

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

... and the resulting log name file- (null) .log

Does anyone see something that I'm missing here, because otherwise it seems to me that this is a mistake?

Thanks at advanvce, Matt

0
source share
1 answer

The answer is here .

You must set the property before creating the registrar.

+3
source

Source: https://habr.com/ru/post/947438/


All Articles