'How can you make two different NLog targets with same date inside?
I have the following two targets defined in NLog.config inside my ASP.NET Core project:
<targets>
<target name="MyApp" xsi:type="File"
fileName="${specialfolder:folder=ApplicationData}/MyApp/${date:format=yyyyMMdd_HHmmss:cached=true}_MyApp.log"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}"
deleteOldFileOnStartup="false"/>
<target name="MyAppAll" xsi:type="File"
fileName="${specialfolder:folder=ApplicationData}/MyApp/${date:format=yyyyMMdd_HHmmss:cached=true}_MyApp.log"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}"
deleteOldFileOnStartup="false"/>
</targets>
MyApp target logs all my logs from the app while MyAppAll includes some framework logs as well.
I am trying to get the NLog to create two log files that have the same timestamp but what I have observed is that MyAppAll will be created immediately on app start since this is the time framework logs start while MyApp will only be created once I send request to API and the result is that I have two files with different dates.
Any ideas on how to solve this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|