Skip to content

Commit 91d76da

Browse files
committed
Add additional message definitions
and refactor class hierarchy
1 parent 1b12002 commit 91d76da

17 files changed

+472
-246
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
<PackageLicenseFile>LICENSE</PackageLicenseFile>
2020
<PackageProjectUrl>https://github.com/astar-development/astar-dev-logging-extensions</PackageProjectUrl>
2121
<PackageReadmeFile>README.md</PackageReadmeFile>
22-
<PackageReleaseNotes>Add LoggerMessage.Define methods</PackageReleaseNotes>
22+
<PackageReleaseNotes>Add more LoggerMessage.Define methods</PackageReleaseNotes>
2323
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
2424
<RepositoryType>git</RepositoryType>
2525
<RepositoryUrl>https://github.com/astar-development/astar-dev-logging-extensions.git</RepositoryUrl>
2626
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2727
<TargetFramework>net9.0</TargetFramework>
2828
<Title>AStar.Dev.Logging.Extensions</Title>
29-
<Version>0.5.0</Version>
29+
<Version>0.5.2</Version>
3030
</PropertyGroup>
3131

3232

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

Lines changed: 139 additions & 39 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ internal static class AStarEventIdList
1212
public static readonly EventId HealthCheckStart = new (2_000, "HealthCheck - Start");
1313
public static readonly EventId HealthCheckSuccess = new (2_001, "HealthCheck - Success");
1414
public static readonly EventId HealthCheckWarning = new (2_002, "HealthCheck - Warning");
15-
public static readonly EventId HealthCheckFailure = new (2_002, "HealthCheck - Failure");
15+
public static readonly EventId HealthCheckFailure = new (2_003, "HealthCheck - Failure");
16+
public static readonly EventId ApiCallStart = new (2_004, "ApiCall - Start");
17+
public static readonly EventId ApiCallSuccess = new (2_005, "ApiCall - Success");
18+
public static readonly EventId ApiCallWarning = new (2_006, "ApiCall - Warning");
19+
public static readonly EventId ApiCallFailure = new (2_007, "ApiCall - Failure");
1620
}

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

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,8 @@ namespace AStar.Dev.Logging.Extensions;
44
/// The <see cref="AStarEventIds" /> class contains the defined <see cref="Microsoft.Extensions.Logging.EventId" /> events available for logging
55
/// Stand-alone <see cref="Microsoft.Extensions.Logging.EventId" /> events can be defined but care should be taken to avoid reusing the values used here
66
/// </summary>
7-
public static class AStarEventIds
7+
public static partial class AStarEventIds
88
{
9-
/// <summary>
10-
/// The <see cref="Ui" /> class defines, yep, the EventIds for logging UI-related errors
11-
/// </summary>
12-
public static class Ui
13-
{
14-
/// <summary>
15-
/// Gets the <see cref="EventId" /> preconfigured for logging a page view
16-
/// </summary>
17-
public static EventId PageView => AStarEventIdList.PageView;
18-
}
19-
20-
/// <summary>
21-
/// The <see cref="Common" /> class defines, yep, the EventIds for logging Common (shared) errors
22-
/// </summary>
23-
public static class Common
24-
{
25-
/// <summary>
26-
/// Gets the <see cref="EventId" /> preconfigured for logging an error
27-
/// </summary>
28-
public static EventId ExceptionId => AStarEventIdList.Error;
29-
30-
/// <summary>
31-
/// Gets the <see cref="EventId" /> preconfigured for logging a critical error
32-
/// </summary>
33-
public static EventId CriticalEventId => AStarEventIdList.CriticalError;
34-
}
35-
369
/// <summary>
3710
/// The <see cref="Api" /> class defines, yep, the EventIds for logging API-related errors
3811
/// </summary>
@@ -57,5 +30,25 @@ public static class Api
5730
/// Gets the <see cref="EventId" /> preconfigured for logging a HealthCheck failure
5831
/// </summary>
5932
public static EventId HealthCheckFailure => AStarEventIdList.HealthCheckFailure;
33+
34+
/// <summary>
35+
/// Gets the <see cref="EventId" /> preconfigured for logging an API Call success
36+
/// </summary>
37+
public static EventId ApiCallStart => AStarEventIdList.ApiCallStart;
38+
39+
/// <summary>
40+
/// Gets the <see cref="EventId" /> preconfigured for logging an API Call success
41+
/// </summary>
42+
public static EventId ApiCallSuccess => AStarEventIdList.ApiCallSuccess;
43+
44+
/// <summary>
45+
/// Gets the <see cref="EventId" /> preconfigured for logging an API Call warning
46+
/// </summary>
47+
public static EventId ApiCallWarning => AStarEventIdList.ApiCallWarning;
48+
49+
/// <summary>
50+
/// Gets the <see cref="EventId" /> preconfigured for logging an API Call failure
51+
/// </summary>
52+
public static EventId ApiCallFailure => AStarEventIdList.ApiCallFailure;
6053
}
6154
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace AStar.Dev.Logging.Extensions;
2+
3+
/// <summary>
4+
/// The <see cref="AStarEventIds" /> class contains the defined <see cref="Microsoft.Extensions.Logging.EventId" /> events available for logging
5+
/// Stand-alone <see cref="Microsoft.Extensions.Logging.EventId" /> events can be defined but care should be taken to avoid reusing the values used here
6+
/// </summary>
7+
public static partial class AStarEventIds
8+
{
9+
/// <summary>
10+
/// The <see cref="Common" /> class defines, yep, the EventIds for logging Common (shared) errors
11+
/// </summary>
12+
public static class Common
13+
{
14+
/// <summary>
15+
/// Gets the <see cref="EventId" /> preconfigured for logging an error
16+
/// </summary>
17+
public static EventId ExceptionId => AStarEventIdList.Error;
18+
19+
/// <summary>
20+
/// Gets the <see cref="EventId" /> preconfigured for logging a critical error
21+
/// </summary>
22+
public static EventId CriticalEventId => AStarEventIdList.CriticalError;
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace AStar.Dev.Logging.Extensions;
2+
3+
/// <summary>
4+
/// The <see cref="AStarEventIds" /> class contains the defined <see cref="Microsoft.Extensions.Logging.EventId" /> events available for logging
5+
/// Stand-alone <see cref="Microsoft.Extensions.Logging.EventId" /> events can be defined but care should be taken to avoid reusing the values used here
6+
/// </summary>
7+
public static partial class AStarEventIds
8+
{
9+
/// <summary>
10+
/// The <see cref="Ui" /> class defines, yep, the EventIds for logging UI-related errors
11+
/// </summary>
12+
public static class Ui
13+
{
14+
/// <summary>
15+
/// Gets the <see cref="EventId" /> preconfigured for logging a page view
16+
/// </summary>
17+
public static EventId PageView => AStarEventIdList.PageView;
18+
}
19+
}

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

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,61 @@
11
namespace AStar.Dev.Logging.Extensions;
22

33
/// <summary>
4+
/// The <see cref="AStarLogger{TCategoryName}"/> class supplies the currently supported, predefined, Log Messages.
5+
/// There is an additional <seealso cref="Log{TState}"/> method for any currently not implemented log message
46
/// </summary>
5-
/// <param name="loggerMessageDefinitions"></param>
6-
/// <param name="logger"></param>
7-
/// <param name="telemetryClient"></param>
8-
/// <typeparam name="TCategoryName"></typeparam>
9-
public class AStarLogger<TCategoryName>(LoggerMessageDefinitions loggerMessageDefinitions, ILogger<TCategoryName> logger, IAStarTelemetryClient telemetryClient) : ILoggerAstar<TCategoryName>
7+
/// <param name="logger">The underlying instance of <see cref="ILogger{TCategoryName}"/> that will perform the actual logging</param>
8+
/// <param name="telemetryClient">An instance of the <see cref="IAStarTelemetryClient"/> to perform the Application Insights-specific logging (e.g.: Page View)</param>
9+
/// <typeparam name="TCategoryName">The Logging type</typeparam>
10+
public class AStarLogger<TCategoryName>(ILogger<TCategoryName> logger, IAStarTelemetryClient telemetryClient) : ILoggerAstar<TCategoryName>
1011
{
1112
/// <inheritdoc />
1213
public void LogPageView(string pageName)
1314
{
14-
loggerMessageDefinitions.PageViewLogMessage(logger, pageName, null);
15+
LoggerMessageDefinitionsUi.PageViewLogMessage(logger, pageName, null);
1516

1617
telemetryClient.TrackPageView(pageName);
1718
}
1819

1920
/// <inheritdoc />
2021
public void LogHealthCheckStart(string apiName)
21-
=> loggerMessageDefinitions.HealthCheckStart(logger, apiName, null);
22+
=> LoggerMessageDefinitionsApi.HealthCheckStart(logger, apiName, null);
2223

2324
/// <inheritdoc />
2425
public void LogHealthCheckSuccess(string apiName)
25-
=> loggerMessageDefinitions.HealthCheckSuccess(logger, apiName, null);
26+
=> LoggerMessageDefinitionsApi.HealthCheckSuccess(logger, apiName, null);
2627

2728
/// <inheritdoc />
2829
public void LogHealthCheckWarning(string apiName, string warningMessage)
29-
=> loggerMessageDefinitions.HealthCheckWarning(logger, apiName, warningMessage, null);
30+
=> LoggerMessageDefinitionsApi.HealthCheckWarning(logger, apiName, warningMessage, null);
3031

3132
/// <inheritdoc />
3233
public void LogHealthCheckFailure(string apiName, string failureMessage)
33-
=> loggerMessageDefinitions.HealthCheckFailure(logger, apiName, failureMessage, null);
34+
=> LoggerMessageDefinitionsApi.HealthCheckFailure(logger, apiName, failureMessage, null);
3435

3536
/// <inheritdoc />
3637
public void LogException(Exception exception)
37-
=> loggerMessageDefinitions.ExceptionLogMessage(logger, exception.GetBaseException().Message, exception);
38+
=> LoggerMessageDefinitionsCommon.ExceptionLogMessage(logger, exception.GetBaseException().Message, exception);
3839

3940
/// <inheritdoc />
4041
public void LogCriticalFailure(Exception exception)
41-
=> loggerMessageDefinitions.CriticalFailure(logger, exception.GetBaseException().Message, exception);
42+
=> LoggerMessageDefinitionsCommon.CriticalFailure(logger, exception.GetBaseException().Message, exception);
43+
44+
/// <inheritdoc />
45+
public void LogApiCallStart(string apiName, string uri)
46+
=> LoggerMessageDefinitionsApi.ApiCallStart(logger, apiName, uri, null);
47+
48+
/// <inheritdoc />
49+
public void LogApiCallSuccess(string apiName, string uri)
50+
=> LoggerMessageDefinitionsApi.ApiCallSuccess(logger, apiName, uri, null);
51+
52+
/// <inheritdoc />
53+
public void LogApiCallWarning(string apiName, string uri, string warningMessage)
54+
=> LoggerMessageDefinitionsApi.ApiCallWarning(logger, apiName, uri, warningMessage, null);
55+
56+
/// <inheritdoc />
57+
public void LogApiCallFailed(string apiName, string uri, string failureMessage)
58+
=> LoggerMessageDefinitionsApi.ApiCallFailure(logger, apiName, uri, failureMessage, null);
4259

4360
/// <inheritdoc />
4461
public IDisposable? BeginScope<TState>(TState state)

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,34 @@ public interface ILoggerAstar<out T> : ILogger<T>
4949
/// </summary>
5050
/// <param name="exception">An instance of the Exception (or derived type) that occurred</param>
5151
void LogCriticalFailure(Exception exception);
52+
53+
/// <summary>
54+
/// The LogApiCallStart method logs the call (using the Debug level) for the specified API
55+
/// </summary>
56+
/// <param name="apiName">The name of the API being called</param>
57+
/// <param name="uri">The URI being called</param>
58+
void LogApiCallStart(string apiName, string uri);
59+
60+
/// <summary>
61+
/// The LogApiCallSuccess method logs the call (using the Debug level) to the specified API
62+
/// </summary>
63+
/// <param name="apiName">The name of the API being called</param>
64+
/// <param name="uri">The URI being called</param>
65+
void LogApiCallSuccess(string apiName, string uri);
66+
67+
/// <summary>
68+
/// The LogApiCallWarning method logs the call (using the Warning level) for the specified API
69+
/// </summary>
70+
/// <param name="apiName">The name of the API being called</param>
71+
/// <param name="uri">The URI being called</param>
72+
/// <param name="warningMessage">The warning message to log</param>
73+
void LogApiCallWarning(string apiName, string uri, string warningMessage);
74+
75+
/// <summary>
76+
/// The LogApiCallFailed method logs the call (using the Error level) for the specified API
77+
/// </summary>
78+
/// <param name="apiName">The name of the API being called</param>
79+
/// <param name="uri">The URI being called</param>
80+
/// <param name="failureMessage">The failure message to log</param>
81+
void LogApiCallFailed(string apiName, string uri, string failureMessage);
5282
}

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

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)