Richard
Richard

Reputation: 22016

Whats wrong with my log4net configuration?

I have an ASP.NET MVC app which has a bootstrapper class that configures log4net during application startup as follows:

public static void Configure(IApplicationContext applicationContext)
{
    var appender = new log4net.Appender.FileAppender
    {
        Layout = new log4net.Layout.PatternLayout("%d [%t]%-5p %c [%x] <%X{auth}> - %m%n"),
        File = applicationContext.GetLogFile().FullName
    };

    BasicConfigurator.Configure(appender);
}

I have checked that when I call the logging function later that the repository is configured:

LogManager.GetRepository().Configured

this returns true.

The location of applicationContext.GetLogFile().FullName exists and also has permissions set for any user to be able to create and modify files, so I don't quite understand why this fails to create a log file or output any data.

Now I know you can use config files and XML in the Web.config but because the log file location and configuration will change from site to site I need to do this in code.

Please can someone help me.

Upvotes: 1

Views: 205

Answers (1)

Oliver
Oliver

Reputation: 45071

you should add an

appender.ActivateOptions();

Upvotes: 3

Related Questions