-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add syslog style log levels to IoT Edge logs (#942)
* Add severity to log messages * Add comment * Add comment * Fix test changes * Fix Logger test after refactor
- Loading branch information
1 parent
864b33d
commit 951afd8
Showing
2 changed files
with
110 additions
and
15 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
60 changes: 60 additions & 0 deletions
60
edge-util/test/Microsoft.Azure.Devices.Edge.Util.Test/LoggerTest.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,60 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
namespace Microsoft.Azure.Devices.Edge.Util.Test | ||
{ | ||
using System.Collections.Generic; | ||
using Microsoft.Azure.Devices.Edge.Util.Test.Common; | ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
using Serilog.Configuration; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
using Xunit; | ||
using ILogger = Microsoft.Extensions.Logging.ILogger; | ||
using Logger = Microsoft.Azure.Devices.Edge.Util.Logger; | ||
|
||
[Unit] | ||
public class LoggerTest | ||
{ | ||
[Fact] | ||
public void SeverityTest() | ||
{ | ||
var testSink = new TestSink(); | ||
|
||
LoggerConfiguration TestSinkMap(LoggerSinkConfiguration loggerSinkConfiguration) | ||
=> loggerSinkConfiguration.Sink(testSink); | ||
|
||
ILogger logger = Logger.GetLoggerFactory(LogEventLevel.Debug, TestSinkMap).CreateLogger("test"); | ||
Assert.NotNull(logger); | ||
|
||
logger.LogInformation("Test message"); | ||
List<LogEvent> emittedEvents = testSink.GetEmittedEvents(); | ||
Assert.Equal("6", emittedEvents[0].Properties["Severity"].ToString()); | ||
testSink.Reset(); | ||
|
||
logger.LogDebug("Test message"); | ||
emittedEvents = testSink.GetEmittedEvents(); | ||
Assert.Equal("7", emittedEvents[0].Properties["Severity"].ToString()); | ||
testSink.Reset(); | ||
|
||
logger.LogWarning("Test message"); | ||
emittedEvents = testSink.GetEmittedEvents(); | ||
Assert.Equal("4", emittedEvents[0].Properties["Severity"].ToString()); | ||
testSink.Reset(); | ||
|
||
logger.LogError("Test message"); | ||
emittedEvents = testSink.GetEmittedEvents(); | ||
Assert.Equal("3", emittedEvents[0].Properties["Severity"].ToString()); | ||
} | ||
|
||
class TestSink : ILogEventSink | ||
{ | ||
List<LogEvent> emittedEvents = new List<LogEvent>(); | ||
|
||
public void Emit(LogEvent logEvent) => this.emittedEvents.Add(logEvent); | ||
|
||
public List<LogEvent> GetEmittedEvents() => this.emittedEvents; | ||
|
||
public void Reset() => this.emittedEvents = new List<LogEvent>(); | ||
} | ||
} | ||
} |