SolTechnology.Core.Logging
0.5.0
dotnet add package SolTechnology.Core.Logging --version 0.5.0
NuGet\Install-Package SolTechnology.Core.Logging -Version 0.5.0
<PackageReference Include="SolTechnology.Core.Logging" Version="0.5.0" />
<PackageVersion Include="SolTechnology.Core.Logging" Version="0.5.0" />
<PackageReference Include="SolTechnology.Core.Logging" />
paket add SolTechnology.Core.Logging --version 0.5.0
#r "nuget: SolTechnology.Core.Logging, 0.5.0"
#:package SolTechnology.Core.Logging@0.5.0
#addin nuget:?package=SolTechnology.Core.Logging&version=0.5.0
#tool nuget:?package=SolTechnology.Core.Logging&version=0.5.0
Overview
The SolTechnology.Core.Logging library provides set of Ilogger extensions working well with Application Insights.
Registration
For installing the library, reference SolTechnology.Core.Logging nuget package.
Configuration
No extra configuration is needed.
Usage
builder.Services.AddLogging(c =>
c.AddConsole()
.AddApplicationInsights());
appsettings:
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
},
"Debug": {
"LogLevel": {
"Default": "Trace",
"Microsoft.Hosting": "Trace",
"Microsoft": "Trace",
"Microsoft.Hosting.Lifetime": "Trace"
}
},
"ApplicationInsights": {
"sampling": {
"isEnabled": true,
"maxTelemetryItemsPerSecond": 100
},
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
Operation scope:
- Begin operation scope (creates a custom dimension - key useful for App Insights tracking)
using (_logger.BeginOperationScope(new KeyValuePair<string, object>(command.LogScope.OperationIdName, command.LogScope.OperationId)))
- Log operation (action, method, execution) started status
_logger.OperationStarted(command.LogScope.OperationName);
- Log operation succeeded or failed status
_logger.OperationSucceeded(command.LogScope.OperationName);
_logger.OperationFailed(command.LogScope.OperationName, e);
Middleware:
- Reference middleware
app.UseMiddleware<LoggingMiddleware>();
- Expand log scope with whatever data is helpful from request body, path or query
_logger.AddToScope("userId", userId.ToString() ?? "unknown"),
Usage Example result
| Timestamp | Message | CustomDimensions.PlayerId |
|---|---|---|
| 4/11/2022, 12:00:10.738 AM | Operation: [CalculatePlayerStatistics]. Status: [START] | 44 |
| 4/11/2022, 12:00:12.859 AM | Operation: [CalculatePlayerStatistics]. Status: [SUCCESS] | 44 |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Http (>= 2.3.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- Microsoft.Extensions.Options (>= 10.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SolTechnology.Core.Logging:
| Package | Downloads |
|---|---|
|
SolTechnology.Core.CQRS
Complete CQRS implementation built on MediatR with Result pattern, SuperChain for complex workflows, automatic FluentValidation, and logging pipeline behaviors. Enforces clean separation between reads and writes with explicit success/failure handling. |
GitHub repositories
This package is not used by any popular GitHub repositories.