public static TraceWriterConfig TraceToList(this TraceManagerConfig traceManagerConfig, IList <TraceEntry> list, SwitchSet switchSet) { Contract.Requires <ArgumentNullException>(traceManagerConfig != null); Contract.Requires <ArgumentNullException>(list != null); Contract.Requires <ArgumentNullException>(switchSet != null); var listLogWriterConfig = new ListLogWriterConfig <TraceEntry>() { List = list }; return(TraceTo(traceManagerConfig, listLogWriterConfig, switchSet)); }
public void MissingLogWriterConfigThrows() { var logManager = new LogManager(); // LogManager.GetLogWriter throws on no match var missingConfig = new ListLogWriterConfig <TraceEntry>(); Assert.Throws <KeyNotFoundException>(() => logManager.GetLogWriter(missingConfig)); Assert.True(logManager.IsHealthy); // LogManager.GetEntryWriter also throws Assert.Throws <KeyNotFoundException>(() => logManager.GetEntryWriter <TraceEntry>(missingConfig)); }
public async Task SettingUpHttpLoggingTwiceWorks() { LogManager logManager = null; // Log targets var stringWriter = new StringWriter(); var listRequestEntries = new List <HttpRequestEntry>(); var listResponseEntries = new List <HttpResponseEntry>(); var listTraceEntries = new List <TraceEntry>(); var testServer = TestServer.Create(owinAppBuilder => { // Save this for asserts below logManager = owinAppBuilder.GetLogManager(); var logManagerConfig = owinAppBuilder.GetLogManagerConfig(); logManagerConfig.UseTextWriter(stringWriter); logManagerConfig.UseTestOutput(_testOutput); Assert.Equal(2, logManagerConfig.Writers.Count); // Enable HTTP logging #1 owinAppBuilder.LogHttpRequestsToAll(); // Add ListLogWriters for requests and responses var requestListConfig = new ListLogWriterConfig <HttpRequestEntry>() { List = listRequestEntries }; var responseListConfig = new ListLogWriterConfig <HttpResponseEntry>() { List = listResponseEntries }; logManagerConfig.Writers.Add(requestListConfig); logManagerConfig.Writers.Add(responseListConfig); // Enable HTTP logging #2 owinAppBuilder.LogHttpRequests(new ILogWriterConfig[] { requestListConfig, responseListConfig }); // Trace to list, too owinAppBuilder.GetTraceManagerConfig().TraceToList(listTraceEntries); }); using (testServer) { // Single request, expect a 404 as no handler was setup var response = await testServer.HttpClient.GetAsync("no-page-here.html"); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // Second request, expect a 404 as no handler was setup response = await testServer.HttpClient.GetAsync("no-page-here2.html"); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } // There should be no setup errors Assert.Empty(logManager.SetupLog.Where(traceEntry => traceEntry.TraceLevel > TraceLevel.Info)); Assert.NotEmpty(listRequestEntries); Assert.NotEmpty(listResponseEntries); Assert.Equal(404, listResponseEntries.First().HttpStatusCode); }