MSHelper.Logging 1.0.0

dotnet add package MSHelper.Logging --version 1.0.0
NuGet\Install-Package MSHelper.Logging -Version 1.0.0
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="MSHelper.Logging" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MSHelper.Logging --version 1.0.0
#r "nuget: MSHelper.Logging, 1.0.0"
#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 MSHelper.Logging as a Cake Addin
#addin nuget:?package=MSHelper.Logging&version=1.0.0

// Install MSHelper.Logging as a Cake Tool
#tool nuget:?package=MSHelper.Logging&version=1.0.0

MSHelper.Logging : Centralized logging with Serilog and Seq.

⭐ Star us on GitHub � it motivates us a lot!

Overview

Adds the logging capability, by default uses Serilog for logging with 3 optional extensions (sinks):

--- Console

--- File

--- Seq

Installation

This document is for the latest MSHelper.Logging 1.0.0 release and later.

dotnet add package MSHelper.Logging

Dependencies

-- MSHelper

Usage

Extend Program.cs → CreateDefaultBuilder() with UseLogging() that will add the required services and configure ILogger available in ASP.NET Core framework.

public static IWebHostBuilder GetWebHostBuilder(string[] args)
    => WebHost.CreateDefaultBuilder(args)
        .ConfigureServices(services => services.AddMSHelper().Build())
        .UseLogging();

Then, simply inject ILogger<T> (being ASP.NET Core built-in abstraction) to write the logs.

public class SomeService
{
    private readonly ILogger<SomeService> _logger;

    public SomeService(ILogger<SomeService> logger)
    {
        _logger = logger;
    }

    public void Foo()
    {
        _logger.LogInformation("Foo");
    }
}

Options

--- applicationName - sets the optional application name property used for log enrichment.

--- serviceId - sets the optional service id property used for log enrichment.

--- excludePaths - optional endpoints that should be excluded from logging (e.g. while performing the health checks by other services).

--- console.enabled - enables/disables console logger.

--- file.enabled - enables/disables file logger.

--- file.path - path to the file logs.

--- file.interval - how often should the new file with logs be created.

--- seq.enabled - enables/disables Seq logger.

--- seq.url - URL to Seq API.

--- seq.token - API key (if provided) used while sending logs to Seq.

appsettings.json

"logger": {
  "level": "information",
  "excludePaths": ["/", "/ping", "/metrics"],
  "excludeProperties": [
    "api_key",
    "access_key",
    "ApiKey",
    "ApiSecret",
    "ClientId",
    "ClientSecret",
    "ConnectionString",
    "Password",
    "Email",
    "Login",
    "Secret",
    "Token"
  ],
  "console": {
    "enabled": true
  },
  "elk": {
    "enabled": false,
    "url": "http://localhost:9200"
  },
  "file": {
    "enabled": true,
    "path": "logs/logs.txt",
    "interval": "day"
  },
  "seq": {
    "enabled": true,
    "url": "http://localhost:5341",
    "apiKey": "secret"
  },
  "tags": {}
},

Important Note:

All the MSHelper packages are for self learning purposes inspired by Devmentors.io

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.

NuGet packages (1)

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

Package Downloads
MSHelper.Logging.CQRS

MSHelper.Logging.CQRS - Centralized logging for CQRS with Serilog and Seq.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 233 10/25/2022