public void Dispose_HappyPath_FlushLogFactory() { // Arrange var provider = new NLogLoggerProvider(); var internalLogWriter = CaptureInternalLog(); // Act provider.Dispose(); // Assert var internalLog = internalLogWriter.ToString(); Assert.Contains("LogFactory.Flush", internalLog, StringComparison.OrdinalIgnoreCase); }
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); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { var logProvider = new NLogLoggerProvider(); try { loggerFactory.AddConsole(); loggerFactory.AddDebug(LogLevel.Information); loggerFactory?.AddProvider(logProvider); app.UseMvc(); var options = new DefaultFilesOptions(); options.DefaultFileNames.Clear(); options.DefaultFileNames.Add("default.htm"); app.UseDefaultFiles(options); app.UseStaticFiles(); } finally { logProvider.Dispose(); } }