NLog per session
Is there a way to configure NLog to log information per application session? At the moment it adds messages to the log file every time the application is executed (WinForm). We would only like to store information about the current session. This means that when the application starts, all previous messages are cleared before registering any new message. Thus, only messages from the current sessions will be available in the log file.
Here is the current configuration
<?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>
thanks
+2
a source to share
1 answer
Assuming you can only open one instance of your application at a time, you can simply use the deleteOldFileOnStartup parameter:
<targets>
<target name="FileTarget" xsi:type="File" fileName="MainLogFile.txt" layout="${longdate} ${callsite} ${level} ${message}" deleteOldFileOnStartup="true">
</targets>
+2
a source to share