简体   繁体   English

NLog有时不写入文件

[英]NLog sometimes it doesn't write to file

In my C#, I'm working a library (Outlook Add-in). 在C#中,我正在使用一个库(Outlook加载项)。

I'm using NLog for .NET 3.5 我正在使用NLog for .NET 3.5

The problem is that on my development machine, sometimes NLog doesn't write the logs to the file. 问题是在我的开发计算机上,有时NLog不会将日志写入文件。

I'm using NLog version 2.0.0.0 and the problem occours with Windows 8.1 Pro 我正在使用NLog 2.0.0.0版,并且Windows 8.1 Pro出现了问题

Here is the App.config 这是App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  </configSections>

  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
      <target name="file" xsi:type="File"
              fileName="${specialfolder:folder=ApplicationData}\\AppName\\Logs\\log.txt"
              archiveEvery="Day"
              archiveNumbering="Rolling"
              maxArchiveFiles="30"
              layout="${date:format=yyyy-MM-dd HH\:mm\:ss} ${level:uppercase=true} ${logger} - ${message} ${exception:format=tostring}"/>
    </targets>
    <rules>
      <logger name="*" minlevel="Debug" writeTo="file"/>
    </rules>
  </nlog>

  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>

</configuration>

In the distribution, currently I do not include the file NLog.config, but also including it, I haven't seen any change 在发行版中,当前我不包括文件NLog.config,但也包括它,我没有看到任何更改

The one below is the method in which the problem occours, should I have to include special libraries in my distribution? 下面的一种是出现问题的方法,我是否应该在发行版中包括特殊的库? (Like stdole.dll as example?) (例如,以stdole.dll为例?)

    private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
    {
        String aversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
        log.Debug("AddinStartupComplete called version: {0}", aversion);
    }

Ok, it seems I have found a solution. 好的,看来我找到了解决方案。
First of all, I modified the App.config file as follows: 首先,我修改了App.config文件,如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>

</configuration>

Then I included a file NLog.config as follows: 然后,我包含一个文件NLog.config,如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <targets> 
    <target name="file" xsi:type="File" 
            fileName="${specialfolder:folder=ApplicationData}\\AppName\\Logs\\log.txt"
            archiveEvery="Day"
            archiveNumbering="Rolling"
            maxArchiveFiles="30"            
            layout="${date:format=yyyy-MM-dd HH\:mm\:ss} ${level:uppercase=true} ${logger} - ${message} ${exception:format=tostring}"/>
  </targets> 

  <rules>
    <logger name="*" minlevel="Debug" writeTo="file"/>      
  </rules> 

</nlog>

I also specified to include in the setup the file adxloader64.dll, though the compiler would give me a warning saying that the resource was not compatible with the type of setup specified: x86. 我还指定在安装程序中包含文件adxloader64.dll,尽管编译器会警告我该资源与指定的安装程序类型不兼容:x86。

Note: I'm building a setup using Add-in Express 7.4.x 注意:我正在使用Add-in Express 7.4.x构建安装程序

Now there is just one point to clarify: I should check if this setup works also on a 32-bit Windows system (I have to test it on a Windows 7 home) 现在只需要澄清一点:我应该检查此设置是否也适用于32位Windows系统(我必须在Windows 7家庭版上对其进行测试)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM