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
12 changes: 6 additions & 6 deletions blog-draft.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This guide is for beginner or junior developers (and anyone who enjoys a touch o
- **AStarLogger**: An all-in-one logger and telemetry wonder.
- **LoggingExtensions**: Easy-to-use methods for wiring up Serilog and Application Insights.
- **SerilogConfigure**: The configuration behind AStar logging magic.
- **LogMessageTemplate**: Strongly-typed, reusable logging templates—because why type the same message twice?
- **LogMessage**: Strongly-typed, reusable logging templates—because why type the same message twice?

Ready? Grab your logging toolbox and let’s get started! 🚀

Expand Down Expand Up @@ -105,7 +105,7 @@ What’s happening here? It’s setting up these critical parts:
2. Console output gets formatted with timestamps, log levels, and exceptions.
3. External configuration (`serilogsettings.json`) is loaded.

### 5. **🛠️ LogMessageTemplate: Predefined Messages for Convenience**
### 5. **🛠️ LogMessage: Predefined Messages for Convenience**

Why write the same logging message repeatedly when you can have reusable, strongly-typed templates with `[LoggerMessage]`?
**A Simple Example:**
Expand All @@ -114,10 +114,10 @@ Why write the same logging message repeatedly when you can have reusable, strong
var logger = Substitute.For<ILogger>();

// Log a 400 (Bad Request)
LogMessageTemplate.BadRequest(logger, "/example-path");
LogMessage.BadRequest(logger, "/example-path");

// Log a 404 (Not Found)
LogMessageTemplate.NotFound(logger, "/missing-resource");
LogMessage.NotFound(logger, "/missing-resource");
```

These helper methods will output descriptive log entries like:
Expand Down Expand Up @@ -149,7 +149,7 @@ app.MapGet("/", (ILogger<AStarLogger<string>> logger, ITelemetryClient telemetry

astarLogger.LogPageView("HomePage"); // Logs and tracks telemetry
logger.LogWarning("This is a warning log.");
LogMessageTemplate.NotFound(logger, "/missing-resource");
LogMessage.NotFound(logger, "/missing-resource");

return Results.Ok("Check your logs for structured awesomeness.");
});
Expand All @@ -171,7 +171,7 @@ Searching through unstructured logs is like trying to find Waldo in a snowstorm.
- **👨‍🚀 AStarLogger** combines structured logs with telemetry tracking.
- **🔌 LoggingExtensions** simplifies Serilog and Application Insights configuration.
- **📋 SerilogConfigure** ensures your logs are sent to reliable sinks.
- **🛠️ LogMessageTemplate** makes strongly-typed reusable logs.
- **🛠️ LogMessage** makes strongly-typed reusable logs.

### 🚀 Closing Logs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageId>AStar.Dev.Logging.Extensions</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<PackageReleaseNotes>Add some LoggerMessage templates to cover the core use-cases</PackageReleaseNotes>
<PackageReleaseNotes>Add additional LoggerMessage templates to cover the basic use-cases missed previously</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>Logging Application Insights Serilog LoggerMessage Templates</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand All @@ -31,7 +31,7 @@
<RepositoryUrl>https://github.com/astar-development/astar-dev-logging-extensions.git</RepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Title>AStar.Dev.Logging.Extensions</Title>
<Version>0.6.1</Version>
<Version>0.6.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
78 changes: 65 additions & 13 deletions src/AStar.Dev.Logging.Extensions/AStar.Dev.Logging.Extensions.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/AStar.Dev.Logging.Extensions/AStarLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class AStarLogger<TCategoryName>(ILogger<TCategoryName> logger, IT
public void LogPageView(string pageName)
{
ArgumentNullException.ThrowIfNull(pageName);
LogMessageTemplate.NotFound(logger, "/missing-resource");
LogMessage.NotFound(logger, "/missing-resource");

telemetryClient.TrackPageView(pageName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace AStar.Dev.Logging.Extensions;
/// <summary>
/// Provides static methods for logging specific HTTP-related events using strongly-typed logging templates.
/// </summary>
public static partial class LogMessageTemplate
public static partial class LogMessage
{
/// <summary>
/// Logs an informational message indicating that a specific page has been viewed.
Expand All @@ -15,6 +15,64 @@ public static partial class LogMessageTemplate
[LoggerMessage(EventId = 200, Level = LogLevel.Information, Message = "Page `{PageName}` viewed.")]
public static partial void PageView(ILogger logger, string pageName);

/// <summary>
/// Logs an informational message indicating that a specific page has been viewed.
/// </summary>
/// <param name="logger">The logger to be used for logging the event.</param>
/// <param name="pageName">The name of the page that was viewed.</param>
[LoggerMessage(EventId = 200, Level = LogLevel.Information, Message = "Page `{PageName}` viewed.")]
public static partial void Trace(ILogger logger, string pageName);

/// <summary>
/// Logs a debug message for the specified location.
/// </summary>
/// <param name="logger">The logger to be used for logging the event.</param>
/// <param name="location">The location of the event.</param>
/// <param name="debugMessage">The debug message to log.</param>
[LoggerMessage(EventId = 200, Level = LogLevel.Debug, Message = "{Location} has raised: `{DebugMessage}`.")]
public static partial void Debug(ILogger logger, string location, string debugMessage);

/// <summary>
/// Logs an informational message for the specified location.
/// </summary>
/// <param name="logger">The logger to be used for logging the event.</param>
/// <param name="location">The location of the event.</param>
/// <param name="informationMessage">The information message to log.</param>
[LoggerMessage(EventId = 200, Level = LogLevel.Information, Message = "{Location} has raised: `{InformationMessage}`.")]
public static partial void Information(ILogger logger, string location, string informationMessage);

/// <summary>
/// Logs an informational message with details about a specific API call.
/// </summary>
/// <param name="logger">The logger to be used for logging the event.</param>
/// <param name="location">The location where the event occurred.</param>
/// <param name="httpRequest">A summary of the request.</param>
/// <param name="httpMethod">The HTTP Method (GET / POST etc.)</param>
/// <param name="apiEndpoint">The API Endpoint called.</param>
/// <param name="apiName">The name of the API.</param>
[LoggerMessage(EventId = 200, Level = LogLevel.Information, Message = "{Location} - request: {HttpRequest}, Method: {HttpMethod}, apiEndpoint: {ApiEndpoint}, apiName: {ApiName}.")]
public static partial void Information(ILogger logger, string location, string httpRequest, string httpMethod, string apiEndpoint, string apiName);

/// <summary>
/// Logs a warning message for the specified location.
/// </summary>
/// <param name="logger">The logger to be used for logging the event.</param>
/// <param name="location">The location of the event.</param>
/// <param name="warningMessage">The warning message to log.</param>
[LoggerMessage(EventId = 400, Level = LogLevel.Warning, Message = "{Location} has raised: `{WarningMessage}`.")]
public static partial void Warning(ILogger logger, string location, string warningMessage);

/// <summary>
/// Logs a critical exception event, providing detailed information about the exception type, message, and stack trace.
/// </summary>
/// <param name="logger">The logger used to log the event.</param>
/// <param name="location">The location of the event.</param>
/// <param name="exceptionType">The type of the exception being logged.</param>
/// <param name="exceptionMessage">The message associated with the exception.</param>
/// <param name="exceptionStack">The stack trace of the exception.</param>
[LoggerMessage(EventId = 500, Level = LogLevel.Error, Message = "{Location} encountered {exceptionType} with `{exceptionMessage}`\nExceptionStack: {exceptionStack}")]
public static partial void LogException(ILogger logger, string location, string exceptionType, string exceptionMessage, string exceptionStack);

/// <summary>
/// Logs a warning message for a Bad Request (400) event, including the requested path.
/// </summary>
Expand Down
Loading
Loading