在Debug模式一切正常,但是在release模式下log4net不工作,查了很多资料,终于解决。具体做如下检查修改。

1、检查log4net写入日志文件路径是否正确;

2、检查对应日志文件路径是否有权限;

3、检查程序log4net配置获取路径;

最常见的问题是第三步,一般都是在AssemblyInfo.cs文件中写入如下代码

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", ConfigFileExtension = "config", Watch = true)]

但这个方式在Debug模式下没有问题,但是在release模式下就不好用了,需要在Global.asax文件中具体再次指定配置文件所在位置,例如:

protected void Application_Start(object sender, EventArgs e)
{
  log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~") + @"\log4net.config"));
}

重新编译发布就可以了。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2021-07-05
  • 2022-12-23
  • 2021-10-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2021-07-15
  • 2021-08-16
相关资源
相似解决方案