Log4net不创建日志文件 [英] Log4net Not Creating Log File

查看:79
本文介绍了Log4net不创建日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在配置了log4net的程序上出现错误,但是没有创建日志文件.我确定该程序中已设置了日志记录,因为其他用户已经使用相同的配置文件从相同的配置文件中创建了日志文件,除了我在下面发布的配置文件之外(文件路径除外).我确定我对该路径具有写权限.在程序失败的那一点上,它绝对必须已经通过了日志记录的初始化.

I'm getting an error on a program that has log4net configured, but no log file is being created. I'm certain the logging is set up in the program because other users have created log files from the same, using an identical config file to what I'm posting below (except for the filepath). I'm sure that I have write permissions to the path. At the point where the program fails, it absolutely must have passed the initialization of the logging.

此配置文件中是否出现任何错误,还是有人遇到过类似的问题,并且知道我应该从中获取日志的程序中应该寻找的东西?

Does anything look wrong in this config file, or has anybody experienced a similar issue and know something I should look for within the program I'm trying to get a log from?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="AutoTag" type="System.Configuration.NameValueSectionHandler"/>
    <section name="WindwardReports" type="System.Configuration.NameValueSectionHandler"/>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/>
  </configSections>

  <AutoTag>
    <add key="_debug" value="true"/>
  </AutoTag>

  <WindwardReports>
    <add key="line.break" value="internal"/>
  </WindwardReports>

  <appSettings>
    <add key="sql.timeout" value="240"/>
  </appSettings>

  <log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">

      <param name="File" value="C:\Users\loganm\Documents\Catapult.log"/>

      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="2"/>
      <param name="MaximumFileSize" value="100KB"/>
      <param name="RollingStyle" value="Size"/>
      <param name="StaticLogFileName" value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] ac.server %-5p %c - %m%n"/>
      </layout>
    </appender>

    <root>
      <level value="DEBUG"/>
      <appender-ref ref="RollingFileAppender"/>
    </root>
  </log4net>
</configuration>

推荐答案

在放置日志记录代码之前,请在应用程序中提供以下代码:

Give the following code in your application before you put your logging code:

log4net.Config.XmlConfigurator.Configure();

您可以在Global.asax中定义它:

You can define it in Global.asax:

void Application_Start(object sender, EventArgs e) 
{
    // Code that runs on application startup

    // Initialize log4net.
    log4net.Config.XmlConfigurator.Configure();
}

您还可以按照Kevin的建议添加以下行(是否提及您的配置文件名):

You can also add the following line as Kevin advised (either mentioning your config file name or not):

[assembly: log4net.Config.XmlConfigurator]

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

希望有帮助!

这篇关于Log4net不创建日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆