每会话NLog

每会话NLog,nlog,Nlog,有没有办法将NLog配置为每个应用程序会话记录信息?现在,每次执行应用程序时,它都会在日志文件中追加消息(WinForm)。我们希望只存储当前会话的信息。这意味着当应用程序启动时,在记录任何新消息之前,将清除所有以前的消息。这样,日志文件中将只提供当前会话的消息 这是当前的配置 <?xml version="1.0"?> <nlog autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd"

有没有办法将NLog配置为每个应用程序会话记录信息?现在,每次执行应用程序时,它都会在日志文件中追加消息(WinForm)。我们希望只存储当前会话的信息。这意味着当应用程序启动时,在记录任何新消息之前,将清除所有以前的消息。这样,日志文件中将只提供当前会话的消息

这是当前的配置

 <?xml version="1.0"?>
<nlog autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <targets>
    <target name="FileTarget" xsi:type="File" fileName="MainLogFile.txt" layout="${longdate} ${callsite} ${level} ${message}"/>/>
  </targets>
  <rules>
    <logger name="*" levels="Trace,Info,Warn,Error,Debug,Fatal" writeTo="FileTarget"/>
  </rules>
</nlog>

/>

谢谢

假设一次只能打开应用程序的一个实例,您可以使用deleteOldFileOnStartup参数:

  <targets>
    <target name="FileTarget" xsi:type="File" fileName="MainLogFile.txt" layout="${longdate} ${callsite} ${level} ${message}" deleteOldFileOnStartup="true">
  </targets>

Eric,感谢您的回复。deleteOldFileOnStartup不起作用。它什么也没做。