From 4887a77498a2529309ddd9136fe99bf3d61a3643 Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 4 Mar 2015 17:04:05 -0800 Subject: [PATCH] Logging API changes --- .../ElmCaptureMiddleware.cs | 2 +- .../ElmLogger.cs | 2 +- .../ElmLoggerProvider.cs | 2 +- .../ElmLoggerTest.cs | 50 +++++++++---------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.AspNet.Diagnostics.Elm/ElmCaptureMiddleware.cs b/src/Microsoft.AspNet.Diagnostics.Elm/ElmCaptureMiddleware.cs index a2bd2f963c..b8879ada68 100644 --- a/src/Microsoft.AspNet.Diagnostics.Elm/ElmCaptureMiddleware.cs +++ b/src/Microsoft.AspNet.Diagnostics.Elm/ElmCaptureMiddleware.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Diagnostics.Elm { _next = next; _options = options.Options; - _logger = factory.Create(); + _logger = factory.CreateLogger(); } public async Task Invoke(HttpContext context) diff --git a/src/Microsoft.AspNet.Diagnostics.Elm/ElmLogger.cs b/src/Microsoft.AspNet.Diagnostics.Elm/ElmLogger.cs index 2e25edca93..ebfdc4849d 100644 --- a/src/Microsoft.AspNet.Diagnostics.Elm/ElmLogger.cs +++ b/src/Microsoft.AspNet.Diagnostics.Elm/ElmLogger.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Diagnostics.Elm _store = store; } - public void Write(LogLevel logLevel, int eventId, object state, Exception exception, + public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) { if (!IsEnabled(logLevel) || (state == null && exception == null)) diff --git a/src/Microsoft.AspNet.Diagnostics.Elm/ElmLoggerProvider.cs b/src/Microsoft.AspNet.Diagnostics.Elm/ElmLoggerProvider.cs index 1c74128ee9..d26d8e52a9 100644 --- a/src/Microsoft.AspNet.Diagnostics.Elm/ElmLoggerProvider.cs +++ b/src/Microsoft.AspNet.Diagnostics.Elm/ElmLoggerProvider.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Diagnostics.Elm _options = options; } - public ILogger Create(string name) + public ILogger CreateLogger(string name) { return new ElmLogger(name, _options, _store); } diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/ElmLoggerTest.cs b/test/Microsoft.AspNet.Diagnostics.Tests/ElmLoggerTest.cs index e4fa4a657c..597b740a96 100644 --- a/test/Microsoft.AspNet.Diagnostics.Tests/ElmLoggerTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Tests/ElmLoggerTest.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests var store = new ElmStore(); var options = new ElmOptions() { Filter = filter ?? _filter }; var provider = new ElmLoggerProvider(store, options); - var logger = (ElmLogger)provider.Create(name ?? _name); + var logger = (ElmLogger)provider.CreateLogger(name ?? _name); return new Tuple(logger, store); } @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests var store = t.Item2; // Act - logger.Write(LogLevel.Information, 0, _state, null, null); + logger.Log(LogLevel.Information, 0, _state, null, null); // Assert Assert.Single(store.GetActivities()); @@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests var store = t.Item2; // Act - logger.Write(LogLevel.Information, 0, null, null, null); + logger.Log(LogLevel.Information, 0, null, null, null); // Assert Assert.Empty(store.GetActivities()); @@ -64,11 +64,11 @@ namespace Microsoft.AspNet.Diagnostics.Tests var store = t.Item2; // Act - logger.Write(LogLevel.Verbose, 0, _state, null, null); - logger.Write(LogLevel.Information, 0, _state, null, null); - logger.Write(LogLevel.Warning, 0, _state, null, null); - logger.Write(LogLevel.Error, 0, _state, null, null); - logger.Write(LogLevel.Critical, 0, _state, null, null); + logger.Log(LogLevel.Verbose, 0, _state, null, null); + logger.Log(LogLevel.Information, 0, _state, null, null); + logger.Log(LogLevel.Warning, 0, _state, null, null); + logger.Log(LogLevel.Error, 0, _state, null, null); + logger.Log(LogLevel.Critical, 0, _state, null, null); // Assert Assert.Equal(5, (store.GetActivities().SelectMany(a => NodeLogs(a.Root, new List()))).ToList().Count); @@ -89,11 +89,11 @@ namespace Microsoft.AspNet.Diagnostics.Tests var store = t.Item2; // Act - logger.Write(LogLevel.Verbose, 0, _state, null, null); - logger.Write(LogLevel.Information, 0, _state, null, null); - logger.Write(LogLevel.Warning, 0, _state, null, null); - logger.Write(LogLevel.Error, 0, _state, null, null); - logger.Write(LogLevel.Critical, 0, _state, null, null); + logger.Log(LogLevel.Verbose, 0, _state, null, null); + logger.Log(LogLevel.Information, 0, _state, null, null); + logger.Log(LogLevel.Warning, 0, _state, null, null); + logger.Log(LogLevel.Error, 0, _state, null, null); + logger.Log(LogLevel.Critical, 0, _state, null, null); // Assert Assert.Equal(count, (store.GetActivities().SelectMany(a => NodeLogs(a.Root, new List()))).ToList().Count); @@ -112,13 +112,13 @@ namespace Microsoft.AspNet.Diagnostics.Tests { for (var i = 0; i < 25; i++) { - logger.WriteWarning("hello world"); + logger.LogWarning("hello world"); } using (logger.BeginScope("test15")) { for (var i = 0; i < 25; i++) { - logger.WriteCritical("goodbye world"); + logger.LogCritical("goodbye world"); } } } @@ -142,9 +142,9 @@ namespace Microsoft.AspNet.Diagnostics.Tests workerThread.Start(); using (logger.BeginScope("test1")) { - logger.WriteWarning("hello world"); + logger.LogWarning("hello world"); Thread.Sleep(1000); - logger.WriteCritical("goodbye world"); + logger.LogCritical("goodbye world"); } workerThread.Join(); @@ -168,9 +168,9 @@ namespace Microsoft.AspNet.Diagnostics.Tests workerThread.Start(); using (logger.BeginScope("test2")) { - logger.WriteWarning("hello world"); + logger.LogWarning("hello world"); Thread.Sleep(1000); - logger.WriteCritical("goodbye world"); + logger.LogCritical("goodbye world"); } workerThread.Join(); @@ -239,7 +239,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests { using (logger.BeginScope("test7")) { - logger.WriteVerbose("hi"); + logger.LogVerbose("hi"); } } @@ -258,7 +258,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests // Act using (logger.BeginScope("test8")) { - logger.WriteVerbose("hi"); + logger.LogVerbose("hi"); using (logger.BeginScope("test9")) { } @@ -283,7 +283,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests { using (logger.BeginScope("test11")) { - logger.WriteInformation("hi"); + logger.LogInformation("hi"); } } @@ -320,20 +320,20 @@ namespace Microsoft.AspNet.Diagnostics.Tests { for (var i = 0; i < 5; i++) { - _logger.WriteVerbose(string.Format("xxx {0}", i)); + _logger.LogVerbose(string.Format("xxx {0}", i)); Thread.Sleep(5); } using (_logger.BeginScope("test13")) { for (var i = 0; i < 3; i++) { - _logger.WriteVerbose(string.Format("yyy {0}", i)); + _logger.LogVerbose(string.Format("yyy {0}", i)); Thread.Sleep(200); } } for (var i = 0; i < 7; i++) { - _logger.WriteVerbose(string.Format("zzz {0}", i)); + _logger.LogVerbose(string.Format("zzz {0}", i)); Thread.Sleep(40); } }