Log4Net在部署时不会记录日志 [英] Log4Net doesn't log when deployed

查看:62
本文介绍了Log4Net在部署时不会记录日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用log4net记录我的应用程序(这是WPF应用程序).该日志记录在调试模式下运行良好,但不适用于我的已部署版本.该应用程序安装在C:\ Program Files(x86)\ MyApp中(我使用InnoSetup创建安装程序).在调试模式下,将很好地创建日志文件夹和日志文件.在部署的版本中,什么都没有出现,没有创建日志文件夹.

I'm using log4net to log my application (This is a WPF application). The logging works well in debug mode, but it doesn't work with my deployed version. The application is installed in C:\Program Files (x86)\MyApp (I use InnoSetup to create the installer). In debug mode, the log folder is well created and the log files too. In the deployed version, nothing appears, the log folder isn't created.

这是我的log4net配置:

Here is my log4net configuration:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
    </configSections>    
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
  <log4net>
    <appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="log\main.log" />
      <encoding value="utf-8" />
      <appendToFile value="true" />
      <maximumFileSize value="1000KB" />
      <maxSizeRollBackups value="0" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger: %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="INFO" />
      <appender-ref ref="FileAppender" />
    </root>
  </log4net>
</configuration>

这是我在班级中写日志的方式(此示例来自App.xaml.cs):

This is how I write in logs in my classes (this example is from App.xaml.cs):

protected static readonly ILog log = LogManager.GetLogger(typeof(App));

static App()
{
    log4net.Config.XmlConfigurator.Configure();  
}

private void Application_Startup(object sender, StartupEventArgs e)
{
    log.Info("This is an info log");
}

我尝试将级别值更改为ALL,但没有任何变化.我认为这可能是一个要设置的参数,因为它在调试模式下效果很好(日志文件已在文件夹"x86 \ Debug \ log \"中正确创建.

I've tried to change the level value to ALL, but nothing changes. I think it may be a parameter to set, because it works well in debug mode (the logs files are properly created in the folder "x86\Debug\log\".

我做了一些研究,但对此一无所获.

I've made some researches but I found nothing about that.

推荐答案

听起来像是权限问题:目录权限(和UAC)将阻止您的应用写入C:\ Program Files(x86)以下的任何内容,除非您运行它作为管理员.将日志路径更改为其他位置,例如 $ {LOCALAPPDATA} \ MyApp \ MyApp.log

Sounds like a a permissions issue: Directory permissions (and UAC) will prevent your app from writing to anything below C:\Program Files (x86), unless you run it as admin. Change the log path to somewhere else, for instance ${LOCALAPPDATA}\MyApp\MyApp.log

这篇关于Log4Net在部署时不会记录日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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