-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Diagnostic Listener Logging Adapter
- Loading branch information
1 parent
a463c6f
commit 9897fb3
Showing
9 changed files
with
296 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using Microsoft.Extensions.DiagnosticAdapter; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Rocket.Surgery.Conventions | ||
{ | ||
public class DiagnosticListenerLoggingAdapter | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public DiagnosticListenerLoggingAdapter(ILogger logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[DiagnosticName("Log.Other")] | ||
public void LogOther(LogLevel logLevel, EventId eventId, Exception exception, string message) => _logger.Log(logLevel, eventId, exception, message); | ||
|
||
[DiagnosticName("Log.Trace")] | ||
public void LogTrace(EventId eventId, Exception exception, string message) => _logger.LogTrace(eventId, exception, message); | ||
|
||
[DiagnosticName("Log.Debug")] | ||
public void LogDebug(EventId eventId, Exception exception, string message) => _logger.LogDebug(eventId, exception, message); | ||
|
||
[DiagnosticName("Log.Information")] | ||
public void LogInformation(EventId eventId, Exception exception, string message) => _logger.LogInformation(eventId, exception, message); | ||
|
||
[DiagnosticName("Log.Warning")] | ||
public void LogWarning(EventId eventId, Exception exception, string message) => _logger.LogWarning(eventId, exception, message); | ||
|
||
[DiagnosticName("Log.Error")] | ||
public void LogError(EventId eventId, Exception exception, string message) => _logger.LogError(eventId, exception, message); | ||
|
||
[DiagnosticName("Log.Critical")] | ||
public void LogCritical(EventId eventId, Exception exception, string message) => _logger.LogCritical(eventId, exception, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
test/Conventions.Tests/DiagnosticListenerLoggingAdapterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using FakeItEasy; | ||
using Microsoft.Extensions.Logging; | ||
using Rocket.Surgery.Extensions.Testing; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Rocket.Surgery.Conventions.Tests | ||
{ | ||
public class DiagnosticListenerLoggingAdapterTests : AutoTestBase | ||
{ | ||
public DiagnosticListenerLoggingAdapterTests(ITestOutputHelper outputHelper) : base(outputHelper){} | ||
|
||
[Fact] | ||
public void LogDebug() | ||
{ | ||
var adapter = AutoFake.Resolve<DiagnosticListenerLoggingAdapter>(); | ||
var source = new DiagnosticListener("Test"); | ||
using (source.SubscribeWithAdapter(adapter)) | ||
{ | ||
var logger = new DiagnosticLogger(source); | ||
|
||
logger.LogDebug("test"); | ||
|
||
A.CallTo(() => Logger.Log(LogLevel.Debug, A<EventId>._, A<object>._, A<Exception>._, A<Func<object, Exception, string>>._)) | ||
.MustHaveHappened(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LogTrace() | ||
{ | ||
var adapter = AutoFake.Resolve<DiagnosticListenerLoggingAdapter>(); | ||
var source = new DiagnosticListener("Test"); | ||
using (source.SubscribeWithAdapter(adapter)) | ||
{ | ||
var logger = new DiagnosticLogger(source); | ||
|
||
logger.LogTrace("test"); | ||
|
||
A.CallTo(() => Logger.Log(LogLevel.Trace, A<EventId>._, A<object>._, A<Exception>._, A<Func<object, Exception, string>>._)) | ||
.MustHaveHappened(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LogInformation() | ||
{ | ||
var adapter = AutoFake.Resolve<DiagnosticListenerLoggingAdapter>(); | ||
var source = new DiagnosticListener("Test"); | ||
using (source.SubscribeWithAdapter(adapter)) | ||
{ | ||
var logger = new DiagnosticLogger(source); | ||
|
||
logger.LogInformation("test"); | ||
|
||
A.CallTo(() => Logger.Log(LogLevel.Information, A<EventId>._, A<object>._, A<Exception>._, A<Func<object, Exception, string>>._)) | ||
.MustHaveHappened(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LogCritical() | ||
{ | ||
var adapter = AutoFake.Resolve<DiagnosticListenerLoggingAdapter>(); | ||
var source = new DiagnosticListener("Test"); | ||
using (source.SubscribeWithAdapter(adapter)) | ||
{ | ||
var logger = new DiagnosticLogger(source); | ||
|
||
logger.LogCritical("test"); | ||
|
||
A.CallTo(() => Logger.Log(LogLevel.Critical, A<EventId>._, A<object>._, A<Exception>._, A<Func<object, Exception, string>>._)) | ||
.MustHaveHappened(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LogError() | ||
{ | ||
var adapter = AutoFake.Resolve<DiagnosticListenerLoggingAdapter>(); | ||
var source = new DiagnosticListener("Test"); | ||
using (source.SubscribeWithAdapter(adapter)) | ||
{ | ||
var logger = new DiagnosticLogger(source); | ||
|
||
logger.LogError("test"); | ||
|
||
A.CallTo(() => Logger.Log(LogLevel.Error, A<EventId>._, A<object>._, A<Exception>._, A<Func<object, Exception, string>>._)) | ||
.MustHaveHappened(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void LogWarning() | ||
{ | ||
var adapter = AutoFake.Resolve<DiagnosticListenerLoggingAdapter>(); | ||
var source = new DiagnosticListener("Test"); | ||
using (source.SubscribeWithAdapter(adapter)) | ||
{ | ||
var logger = new DiagnosticLogger(source); | ||
|
||
logger.LogWarning("test"); | ||
|
||
A.CallTo(() => Logger.Log(LogLevel.Warning, A<EventId>._, A<object>._, A<Exception>._, A<Func<object, Exception, string>>._)) | ||
.MustHaveHappened(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.