I am trying to use NLog with XUnit Testing. Working good for the most part except I want to auto delete the log whenever I run a new batch of tests. In reading the "Perfomrance Tuning Options" I thought I could do this, but I can't seem to keep it from deleting the file for each test that is run.
I programmatically set up a new logger as to not mess up the normal applicaion logging and the overcome the My thought was to turn on DeleteOldFileOnStartup, but then use KeepFileOpen and CuncurrentWrites so that all the test threads write to the same file but still have the delete work. This doesn't work!
//setup the test log file
var config = new NLog.Config.LoggingConfiguration();
var logfile = new NLog.Targets.FileTarget(debugLoggerName)
{
FileName = MainTestDir() + testFolder + debugLoggerName + ".txt",
Layout = "${message}",
DeleteOldFileOnStartup = true,
KeepFileOpen = true,
OpenFileCacheTimeout = 120,
ConcurrentWrites = true
};
config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, logfile);
NLog.LogManager.Configuration = config;