简体   繁体   English

我的log4net配置有什么问题?

[英]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: 我有一个ASP.NET MVC应用程序,该应用程序具有引导程序类,该类在应用程序启动期间按以下方式配置log4net:

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. 这返回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. applicationContext.GetLogFile().FullName的位置已存在,并且还为所有用户设置了权限,使其能够创建和修改文件,因此我不太明白为什么它无法创建日志文件或输出任何数据。

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. 现在,我知道您可以在Web.config中使用配置文件和XML,但是由于日志文件的位置和配置会因站点而异,因此我需要在代码中执行此操作。

Please can someone help me. 请有人帮我。

您应该添加一个

appender.ActivateOptions();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM