Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# NLog有时不';无法写入文件_C#_.net_Configuration_Nlog - Fatal编程技术网

C# NLog有时不';无法写入文件

C# NLog有时不';无法写入文件,c#,.net,configuration,nlog,C#,.net,Configuration,Nlog,在我的C#中,我正在使用一个库(Outlook加载项) 我正在为.NET3.5使用NLog 问题是,在我的开发机器上,有时NLog不会将日志写入文件 我使用的是NLog版本2.0.0.0和Windows 8.1 Pro的问题occours 这是App.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="n

在我的C#中,我正在使用一个库(Outlook加载项)

我正在为.NET3.5使用NLog

问题是,在我的开发机器上,有时NLog不会将日志写入文件

我使用的是NLog版本2.0.0.0和Windows 8.1 Pro的问题occours

这是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>

好的,看来我找到了解决办法。
首先,我修改了App.config文件,如下所示:

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

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

</configuration>
<?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>

然后我包括了一个文件NLog.config,如下所示:

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

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

</configuration>
<?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>

我还指定在安装程序中包含文件adxloader64.dll,不过编译器会给我一个警告,指出该资源与指定的安装程序类型x86不兼容

注意:我正在使用外接程序Express 7.4.x构建一个设置


现在只有一点需要澄清:我应该检查此设置是否也适用于32位Windows系统(我必须在Windows 7 home上进行测试)

您是否确定了程序或逻辑中未记录的部分?可能错误发生在该逻辑之前,因此未被记录。是的,事实上,我有一个在模块完成初始化时调用的日志行,调用该行不会对日志文件产生任何写入。如果在该指令之前调用log.Debug,它会被记录?不,我没有,但奇怪的是,当我在调试模式下启动宿主应用程序(在本例中是Outlook)时,日志文件正确地生成了。请看一下