Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TargetFramework>net9.0</TargetFramework>
<Title>AStar.Dev.Logging.Extensions</Title>
<Version>0.5.4</Version>
<Version>0.5.5</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
378 changes: 143 additions & 235 deletions src/AStar.Dev.Logging.Extensions/AStar.Dev.Logging.Extensions.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/AStar.Dev.Logging.Extensions/AStarEventIdList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace AStar.Dev.Logging.Extensions;
/// </summary>
internal static class AStarEventIdList
{
public static readonly EventId Debug = new (1, "Debug");
public static readonly EventId Information = new (2, "Information");
public static readonly EventId Error = new (500, "Error");
public static readonly EventId CriticalError = new (666, "Critical Error");
public static readonly EventId PageView = new (1_000, "Page View");
Expand Down
10 changes: 10 additions & 0 deletions src/AStar.Dev.Logging.Extensions/AStarEventIdsCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,15 @@ public static class Common
/// Gets the <see cref="EventId" /> preconfigured for logging a critical error
/// </summary>
public static EventId CriticalEventId => AStarEventIdList.CriticalError;

/// <summary>
/// Gets the <see cref="EventId" /> preconfigured for logging a critical error
/// </summary>
public static EventId DebugEventId => AStarEventIdList.Debug;

/// <summary>
/// Gets the <see cref="EventId" /> preconfigured for logging a critical error
/// </summary>
public static EventId InformationEventId => AStarEventIdList.Information;
}
}
8 changes: 8 additions & 0 deletions src/AStar.Dev.Logging.Extensions/AStarLoggerCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ namespace AStar.Dev.Logging.Extensions;
/// <typeparam name="TCategoryName">The Logging type</typeparam>
public partial class AStarLogger<TCategoryName>(ILogger<TCategoryName> logger, IAStarTelemetryClient telemetryClient) : ILoggerAstar<TCategoryName>
{
/// <inheritdoc />
public void LogDebug(string message)
=> LoggerMessageDefinitionsCommon.Debug(logger, message, null);

/// <inheritdoc />
public void LogInformation(string message)
=> LoggerMessageDefinitionsCommon.Information(logger, message, null);

/// <inheritdoc />
public void LogException(Exception exception)
=> LoggerMessageDefinitionsCommon.ExceptionOccurred(logger, exception.GetBaseException().Message, exception);
Expand Down
12 changes: 12 additions & 0 deletions src/AStar.Dev.Logging.Extensions/ILoggerAstarCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ namespace AStar.Dev.Logging.Extensions;
/// <typeparam name="T">The type of logger</typeparam>
public partial interface ILoggerAstar<out T> : ILogger<T>
{
/// <summary>
/// The LogDebug method does exactly what its name says
/// </summary>
/// <param name="message">The message to be logged</param>
void LogDebug(string message);

/// <summary>
/// The LogInformation method does exactly what its name says
/// </summary>
/// <param name="message">The message to be logged</param>
void LogInformation(string message);

/// <summary>
/// The LogException method does exactly what its name says
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class LoggerMessageDefinitionsCommon
/// </summary>
public static Action<ILogger, string, Exception?> CriticalFailure => LoggerMessage.Define<string>(
LogLevel.Critical,
AStarEventIds.Common.ExceptionId,
AStarEventIds.Common.CriticalEventId,
"Critical failure: {ErrorMessage}");

/// <summary>
Expand All @@ -19,4 +19,20 @@ public static class LoggerMessageDefinitionsCommon
LogLevel.Error,
AStarEventIds.Common.ExceptionId,
"Error: {ErrorMessage}");

/// <summary>
/// Defines the ExceptionLogMessage message definition
/// </summary>
public static Action<ILogger, string, Exception?> Debug => LoggerMessage.Define<string>(
LogLevel.Error,
AStarEventIds.Common.DebugEventId,
"Error: {ErrorMessage}");

/// <summary>
/// Defines the ExceptionLogMessage message definition
/// </summary>
public static Action<ILogger, string, Exception?> Information => LoggerMessage.Define<string>(
LogLevel.Error,
AStarEventIds.Common.InformationEventId,
"Error: {ErrorMessage}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ namespace AStar.Dev.Logging.Extensions;
[TestSubject(typeof(AStarEventIds.Common))]
public class AStarEventIdsCommonShould
{
[Fact]
public void ContainTheExpectedDebugEventId()
=> AStarEventIds.Common.DebugEventId.Id.ShouldBe(1);

[Fact]
public void ContainTheExpectedDebugName()
=> AStarEventIds.Common.DebugEventId.Name.ShouldBe("Debug");

[Fact]
public void ContainTheExpectedInformationIdEventId()
=> AStarEventIds.Common.InformationEventId.Id.ShouldBe(2);

[Fact]
public void ContainTheExpectedInformationIdName()
=> AStarEventIds.Common.InformationEventId.Name.ShouldBe("Information");

[Fact]
public void ContainTheExpectedExceptionIdEventId()
=> AStarEventIds.Common.ExceptionId.Id.ShouldBe(500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ namespace AStar.Dev.Logging.Extensions;
[TestSubject(typeof(LoggerMessageDefinitionsCommon))]
public class LoggerMessageDefinitionsCommonShould
{
[Fact]
public void DefineTheDebugeMessageAsExpected()
{
var criticalFailure = LoggerMessageDefinitionsCommon.Debug;

criticalFailure.Method.ToString().ShouldBe("Void <Define>b__1(Microsoft.Extensions.Logging.ILogger, System.String, System.Exception)");
criticalFailure.Target?.ToString().ShouldBe("Microsoft.Extensions.Logging.LoggerMessage+<>c__DisplayClass10_0`1[System.String]");
}

[Fact]
public void DefineTheInformationMessageAsExpected()
{
var criticalFailure = LoggerMessageDefinitionsCommon.Information;

criticalFailure.Method.ToString().ShouldBe("Void <Define>b__1(Microsoft.Extensions.Logging.ILogger, System.String, System.Exception)");
criticalFailure.Target?.ToString().ShouldBe("Microsoft.Extensions.Logging.LoggerMessage+<>c__DisplayClass10_0`1[System.String]");
}

[Fact]
public void DefineTheCriticalFailureMessageAsExpected()
{
Expand Down