protected void ConfigureNLog(Targets.Target target = null) { target = target ?? new Targets.MemoryTarget("output") { Layout = "${message}" }; var nlogConfig = new Config.LoggingConfiguration(LoggerProvider.LogFactory); nlogConfig.AddRuleForAllLevels(target); if (target is Targets.Wrappers.WrapperTargetBase wrapperTarget) { nlogConfig.AddTarget(wrapperTarget.WrappedTarget); } LoggerProvider.LogFactory.Configuration = nlogConfig; }
public void Dispose_HappyPath_FlushLogFactory() { // Arrange var logFactory = new LogFactory(); var logConfig = new Config.LoggingConfiguration(logFactory); logConfig.AddTarget(new Targets.MemoryTarget("output")); logConfig.AddRuleForAllLevels(new Targets.Wrappers.BufferingTargetWrapper("buffer", logConfig.FindTargetByName("output"))); logFactory.Configuration = logConfig; var provider = new NLogLoggerProvider(null, logFactory); // Act provider.CreateLogger("test").LogInformation("Hello"); provider.Dispose(); // Assert Assert.Single(logFactory.Configuration.FindTargetByName <Targets.MemoryTarget>("output").Logs); }