NLog不使用ClickOnce进行日志记录

Cor*_*tro 7 .net c# clickonce nlog

我正在通过NLog在我的应用程序中实现日志记录.这是我的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 async="true">
    <target xsi:type="File"
            name="ExceptionTarget"
            fileName="LOG.txt"
            layout="${date:format=dd MMM yyyy HH-mm-ss} ${uppercase:${level}} ${newline}${message} ${exception::maxInnerExceptionLevel=5:format=ToString}${newline}${stacktrace}${newline}"/>
  </targets>

  <targets async="true">
    <target xsi:type="File"
            name="InfoTarget"
            fileName="LOG.txt"
            layout="${date:format=mm-ss} ${uppercase:${level}} ${newline}${message} ${newline}"/>
  </targets>

  <rules>
    <logger name="*" level="Error" writeTo="ExceptionTarget"/>
    <logger name="*" level="Info" writeTo="InfoTarget"/>
  </rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)

当我使用ClickOnce部署应用程序时,没有创建log.txt文件.没有错误发生,我的应用程序正常运行,但没有发生任何事情.

如何解决这个问题呢?

Ser*_*lyi 14

安装软件时,ClickOnce安装程序未部署NLog.config文件,因此您的应用程序没有任何日志记录配置.

解:

  1. 您可以将日志记录配置合并到app.config文件中.
  2. Nlog.config必须具有:构建操作:内容和复制到输出目录:始终复制.