日志文件未在log4net中创建 [英] Log file is not creating in log4net

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

问题描述





我正在尝试使用log4net记录信息/错误。





------------------------------------------- -

谢谢,

Rajeshwari



我尝试了什么:



已将此添加到assemblyinfo.cs文件中



 [assembly:log4net。 Config.XmlConfigurator(Watch = true)] 





和Config文件看起来像这样



<?xml version =1.0encoding =utf-8?> 
< configuration>
< configSections>
< section name =log4nettype =log4net.Config.Log4NetConfigurationSectionHandler,log4net/>
< / configSections>
< log4net>
< root>
< level value =INFO/>
< appender-ref ref =RollingFileAppender/>
< / root>

< appender name =RollingFileAppendertype =log4net.Appender.RollingFileAppender>
< lockingModel type =log4net.Appender.FileAppender + MinimalLock/>
< file value =c:\\LogFiles\\ info.log/>
< staticLogFileName value =true/>
< appendToFile value =true/>
< rollingStyle value =Size/>
< maxSizeRollBackups value =5/>
< maximumFileSize value =1MB/>
< layout type =log4net.Layout.PatternLayout>
< conversionPattern value =%date [%thread]%level%logger - %message%newline/>
< / layout>
< / appender>
< / log4net>

< / configuration>





并调用下面的日志方法



 public static class Logger 
{
private static readonly log4net.ILog log =
log4net.LogManager.GetLogger(System.Reflection。 MethodBase.GetCurrentMethod()DeclaringType)。
public static void LogError(String message)
{
log4net.Config.XmlConfigurator.Configure();
log.Info(应用程序正在运行);
}
}







可能是什么问题?

解决方案

感谢所有代码示例。我创建了一个控制台项目进行复制,没有任何问题。该文件夹在我的机器上开始时不存在它创建并且日志文件写得很好。



我建议你看看你的应用程序有对c:\ logfiles目录的适当权限。



另外一个选项是添加



< pre lang =XML> < appSettings >
< add key = log4net.Internal.Debug value = < span class =code-keyword> true / >
< / appSettings >





到你的.config然后看看log4net正在生成什么调试消息。


Hi,

I am trying to log the info/errors using log4net.


---------------------------------------------
Thanks,
Rajeshwari

What I have tried:

have added this to assemblyinfo.cs file

[assembly: log4net.Config.XmlConfigurator(Watch = true)]



and Config file look like this

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <log4net>
    <root>
      <level value="INFO" />     
      <appender-ref ref="RollingFileAppender" />
    </root>    
    
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <file value="c:\\LogFiles\\info.log" />      
      <staticLogFileName value="true" />
      <appendToFile value="true" />      
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="5" />
      <maximumFileSize value="1MB" />     
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
      </layout>
    </appender>
  </log4net> 
  
</configuration>



and calling the log method like below

public static class Logger
    {
        private static readonly log4net.ILog log =
            log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public static void LogError(String message)
        {
            log4net.Config.XmlConfigurator.Configure();
            log.Info("Application is working");
        }
    }




what might be the problem?

解决方案

Thanks for all the code samples. I created a console project to replicate and had no issues. The folder didn't exist to begin with on my machine it was created and log files wrote to it just fine.

I would suggest looking to see that your app has proper permissions to c:\logfiles directory.

Also another option would be to add

<appSettings>
      <add key="log4net.Internal.Debug" value="true"/>
   </appSettings>



To your .config and then see what debug messages are being generated by log4net.


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

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