0

I like to use more then one log file(with RollingFileAppender) in my C# applications.

The default log is "main.log".

  • The user can create new instance from a user control and can start something in this. I want to log the events into Log filename "log1.log"
  • The next instance of user control write into "log2.log" etc...

How can I configure log4net for this application?

Thanks.

Ruskin
  • 5,721
  • 4
  • 45
  • 62
  • Have you looked at http://stackoverflow.com/questions/10204171/configure-log4net-in-web-application ? – Ruskin Jun 24 '14 at 15:13
  • This not solution for my problem. I can configure log4net, but I unable to configure in my "more then one log file" case. – Zoltán Jun 24 '14 at 15:19

1 Answers1

0

Would something like this work?

http://geekswithblogs.net/rgupta/archive/2009/03/03/dynamic-log-filenames-with-log4net.aspx

You would define the log filename in the log4net config, but have the name be a parameter. You would then set that parameter for the user's instance.

The important part of your config:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="c:\logs\%property{LogName}" />
    <appendToFile value="true" />
    // the rest of your config

Change that {LogName} parameter in code like so:

log4net.GlobalContext.Properties["LogName"] = "user-xyz.log";
Bill Sambrone
  • 4,334
  • 4
  • 48
  • 70