How to create dynamic log4net settings

93 views Asked by At

I'm trying to create dynamic settings for log4net. I need to send logs for different instances, but I don't know their number. Is it possible to create all this in C# code?

1

There are 1 answers

0
Max Brodin On BEST ANSWER

You can do something like this:

Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders(); /*Remove any other appenders*/

foreach (var appender in GetAppenders())
{
   hierarchy.Root.AddAppender(appender);
}

hierarchy.Root.Level = Level.Info;
hierarchy.Configured = true;

Where GetAppenders returns a collection of the IAppender you needed.