Skip to content

Commit bf7b88f

Browse files
authored
Merge pull request #15 from astar-development/features/more-logger-methods
Add Debug and Information with simple parameter
2 parents 179428c + f7fd30e commit bf7b88f

File tree

9 files changed

+227
-237
lines changed

9 files changed

+227
-237
lines changed

src/AStar.Dev.Logging.Extensions/AStar.Dev.Logging.Extensions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2727
<TargetFramework>net9.0</TargetFramework>
2828
<Title>AStar.Dev.Logging.Extensions</Title>
29-
<Version>0.5.4</Version>
29+
<Version>0.5.5</Version>
3030
</PropertyGroup>
3131

3232
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

src/AStar.Dev.Logging.Extensions/AStar.Dev.Logging.Extensions.xml

Lines changed: 143 additions & 235 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AStar.Dev.Logging.Extensions/AStarEventIdList.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace AStar.Dev.Logging.Extensions;
66
/// </summary>
77
internal static class AStarEventIdList
88
{
9+
public static readonly EventId Debug = new (1, "Debug");
10+
public static readonly EventId Information = new (2, "Information");
911
public static readonly EventId Error = new (500, "Error");
1012
public static readonly EventId CriticalError = new (666, "Critical Error");
1113
public static readonly EventId PageView = new (1_000, "Page View");

src/AStar.Dev.Logging.Extensions/AStarEventIdsCommon.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,15 @@ public static class Common
2020
/// Gets the <see cref="EventId" /> preconfigured for logging a critical error
2121
/// </summary>
2222
public static EventId CriticalEventId => AStarEventIdList.CriticalError;
23+
24+
/// <summary>
25+
/// Gets the <see cref="EventId" /> preconfigured for logging a critical error
26+
/// </summary>
27+
public static EventId DebugEventId => AStarEventIdList.Debug;
28+
29+
/// <summary>
30+
/// Gets the <see cref="EventId" /> preconfigured for logging a critical error
31+
/// </summary>
32+
public static EventId InformationEventId => AStarEventIdList.Information;
2333
}
2434
}

src/AStar.Dev.Logging.Extensions/AStarLoggerCommon.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ namespace AStar.Dev.Logging.Extensions;
1212
/// <typeparam name="TCategoryName">The Logging type</typeparam>
1313
public partial class AStarLogger<TCategoryName>(ILogger<TCategoryName> logger, IAStarTelemetryClient telemetryClient) : ILoggerAstar<TCategoryName>
1414
{
15+
/// <inheritdoc />
16+
public void LogDebug(string message)
17+
=> LoggerMessageDefinitionsCommon.Debug(logger, message, null);
18+
19+
/// <inheritdoc />
20+
public void LogInformation(string message)
21+
=> LoggerMessageDefinitionsCommon.Information(logger, message, null);
22+
1523
/// <inheritdoc />
1624
public void LogException(Exception exception)
1725
=> LoggerMessageDefinitionsCommon.ExceptionOccurred(logger, exception.GetBaseException().Message, exception);

src/AStar.Dev.Logging.Extensions/ILoggerAstarCommon.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ namespace AStar.Dev.Logging.Extensions;
99
/// <typeparam name="T">The type of logger</typeparam>
1010
public partial interface ILoggerAstar<out T> : ILogger<T>
1111
{
12+
/// <summary>
13+
/// The LogDebug method does exactly what its name says
14+
/// </summary>
15+
/// <param name="message">The message to be logged</param>
16+
void LogDebug(string message);
17+
18+
/// <summary>
19+
/// The LogInformation method does exactly what its name says
20+
/// </summary>
21+
/// <param name="message">The message to be logged</param>
22+
void LogInformation(string message);
23+
1224
/// <summary>
1325
/// The LogException method does exactly what its name says
1426
/// </summary>

src/AStar.Dev.Logging.Extensions/LoggerMessageDefinitionsCommon.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class LoggerMessageDefinitionsCommon
99
/// </summary>
1010
public static Action<ILogger, string, Exception?> CriticalFailure => LoggerMessage.Define<string>(
1111
LogLevel.Critical,
12-
AStarEventIds.Common.ExceptionId,
12+
AStarEventIds.Common.CriticalEventId,
1313
"Critical failure: {ErrorMessage}");
1414

1515
/// <summary>
@@ -19,4 +19,20 @@ public static class LoggerMessageDefinitionsCommon
1919
LogLevel.Error,
2020
AStarEventIds.Common.ExceptionId,
2121
"Error: {ErrorMessage}");
22+
23+
/// <summary>
24+
/// Defines the ExceptionLogMessage message definition
25+
/// </summary>
26+
public static Action<ILogger, string, Exception?> Debug => LoggerMessage.Define<string>(
27+
LogLevel.Error,
28+
AStarEventIds.Common.DebugEventId,
29+
"Error: {ErrorMessage}");
30+
31+
/// <summary>
32+
/// Defines the ExceptionLogMessage message definition
33+
/// </summary>
34+
public static Action<ILogger, string, Exception?> Information => LoggerMessage.Define<string>(
35+
LogLevel.Error,
36+
AStarEventIds.Common.InformationEventId,
37+
"Error: {ErrorMessage}");
2238
}

tests/AStar.Dev.Logging.Extensions.Tests.Unit/AStarEventIdsCommonShould.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ namespace AStar.Dev.Logging.Extensions;
55
[TestSubject(typeof(AStarEventIds.Common))]
66
public class AStarEventIdsCommonShould
77
{
8+
[Fact]
9+
public void ContainTheExpectedDebugEventId()
10+
=> AStarEventIds.Common.DebugEventId.Id.ShouldBe(1);
11+
12+
[Fact]
13+
public void ContainTheExpectedDebugName()
14+
=> AStarEventIds.Common.DebugEventId.Name.ShouldBe("Debug");
15+
16+
[Fact]
17+
public void ContainTheExpectedInformationIdEventId()
18+
=> AStarEventIds.Common.InformationEventId.Id.ShouldBe(2);
19+
20+
[Fact]
21+
public void ContainTheExpectedInformationIdName()
22+
=> AStarEventIds.Common.InformationEventId.Name.ShouldBe("Information");
23+
824
[Fact]
925
public void ContainTheExpectedExceptionIdEventId()
1026
=> AStarEventIds.Common.ExceptionId.Id.ShouldBe(500);

tests/AStar.Dev.Logging.Extensions.Tests.Unit/LoggerMessageDefinitionsCommonShould.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ namespace AStar.Dev.Logging.Extensions;
55
[TestSubject(typeof(LoggerMessageDefinitionsCommon))]
66
public class LoggerMessageDefinitionsCommonShould
77
{
8+
[Fact]
9+
public void DefineTheDebugeMessageAsExpected()
10+
{
11+
var criticalFailure = LoggerMessageDefinitionsCommon.Debug;
12+
13+
criticalFailure.Method.ToString().ShouldBe("Void <Define>b__1(Microsoft.Extensions.Logging.ILogger, System.String, System.Exception)");
14+
criticalFailure.Target?.ToString().ShouldBe("Microsoft.Extensions.Logging.LoggerMessage+<>c__DisplayClass10_0`1[System.String]");
15+
}
16+
17+
[Fact]
18+
public void DefineTheInformationMessageAsExpected()
19+
{
20+
var criticalFailure = LoggerMessageDefinitionsCommon.Information;
21+
22+
criticalFailure.Method.ToString().ShouldBe("Void <Define>b__1(Microsoft.Extensions.Logging.ILogger, System.String, System.Exception)");
23+
criticalFailure.Target?.ToString().ShouldBe("Microsoft.Extensions.Logging.LoggerMessage+<>c__DisplayClass10_0`1[System.String]");
24+
}
25+
826
[Fact]
927
public void DefineTheCriticalFailureMessageAsExpected()
1028
{

0 commit comments

Comments
 (0)