SolTechnology.Core.Logging 0.2.2

dotnet add package SolTechnology.Core.Logging --version 0.2.2                
NuGet\Install-Package SolTechnology.Core.Logging -Version 0.2.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SolTechnology.Core.Logging" Version="0.2.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SolTechnology.Core.Logging --version 0.2.2                
#r "nuget: SolTechnology.Core.Logging, 0.2.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SolTechnology.Core.Logging as a Cake Addin
#addin nuget:?package=SolTechnology.Core.Logging&version=0.2.2

// Install SolTechnology.Core.Logging as a Cake Tool
#tool nuget:?package=SolTechnology.Core.Logging&version=0.2.2                

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"
      }
    }
  }
Usage
  1. Operation scope:
  1. 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)))
  1. Log operation (action, method, execution) started status
  _logger.OperationStarted(command.LogScope.OperationName);
  1. Log operation succeeded or failed status
   _logger.OperationSucceeded(command.LogScope.OperationName);
   _logger.OperationFailed(command.LogScope.OperationName, e);
  1. Middleware:
  1. Reference middleware
   app.UseMiddleware<LoggingMiddleware>();
  1. Reference middleware

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 Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SolTechnology.Core.Logging:

Package Downloads
SolTechnology.Core.CQRS

SolTechnology Core CQRS library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.2 101 7/23/2024
0.2.1 170 10/6/2023
0.2.0 457 3/29/2022
0.1.0 420 3/4/2022