我的 log4net 配置有什么问题?
我有一个 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);
}
我已经检查过,当我稍后调用日志记录函数时,存储库已配置:
LogManager.GetRepository().Configured
这返回 true。
applicationContext.GetLogFile().FullName
的位置存在,并且还为任何用户设置了能够创建和修改文件的权限,所以我不太明白为什么这无法创建日志文件或输出任何数据。
现在我知道您可以在 Web.config 中使用配置文件和 XML,但由于日志文件位置和配置会因站点而异,因此我需要在代码中执行此操作。
请有人帮助我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该添加一个
you should add an