-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
107 additions
and
47 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
36 changes: 36 additions & 0 deletions
36
src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventLevelExtensions.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,36 @@ | ||
using System; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Sinks.Mongodb.TimeSeries.Extensions | ||
{ | ||
/// <summary> | ||
/// Contains all extensions methods for <see cref="LogEventLevel" />. | ||
/// </summary> | ||
internal static class LogEventLevelExtensions | ||
{ | ||
/// <summary> | ||
/// Converts a <see cref="LogEventLevel" /> into a readable <see cref="string" />. | ||
/// </summary> | ||
/// <param name="level">The <see cref="LogEventLevel" />.</param> | ||
/// <returns> | ||
/// The readable <see cref="string" /> containing the severity. | ||
/// </returns> | ||
/// <exception cref="ArgumentOutOfRangeException"> | ||
/// Thrown when no severity string was found for the current | ||
/// <see cref="LogEventLevel" />. | ||
/// </exception> | ||
internal static string ToSeverityString(this LogEventLevel level) | ||
{ | ||
return level switch | ||
{ | ||
LogEventLevel.Verbose => "verbose", | ||
LogEventLevel.Debug => "debug", | ||
LogEventLevel.Information => "information", | ||
LogEventLevel.Warning => "warning", | ||
LogEventLevel.Error => "error", | ||
LogEventLevel.Fatal => "fatal", | ||
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null) | ||
}; | ||
} | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
tests/Serilog.Sinks.Mongodb.TimeSeries.Tests/Extensions/LogEventLevelExtensionsTests.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,26 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using Serilog.Events; | ||
using Serilog.Sinks.Mongodb.TimeSeries.Extensions; | ||
|
||
namespace Serilog.Sinks.Mongodb.TimeSeries.Tests.Extensions | ||
{ | ||
[TestFixture] | ||
public class LogEventLevelExtensionsTests | ||
{ | ||
[TestCase(LogEventLevel.Debug, "debug")] | ||
[TestCase(LogEventLevel.Verbose, "verbose")] | ||
[TestCase(LogEventLevel.Error, "error")] | ||
[TestCase(LogEventLevel.Fatal, "fatal")] | ||
[TestCase(LogEventLevel.Information, "information")] | ||
[TestCase(LogEventLevel.Warning, "warning")] | ||
public void ShouldGetSeverityString(LogEventLevel level, string expected) | ||
{ | ||
// Act | ||
var result = level.ToSeverityString(); | ||
|
||
// Assert | ||
result.Should().Be(expected); | ||
} | ||
} | ||
} |