Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

flapek/Joint.Logging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Joint.Logging

Branch Build status
master Build Status
develop Build Status

Logging

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

  • Console
  • File
  • Seq

Installation

dotnet add package Joint.Logging

Dependencies

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.AddJoint().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": {
  "applicationName": "some-service",
  "serviceId": "instance-1",
  "excludePaths": ["/ping", "/metrics"],
  "console": {
    "enabled": true
  },
  "file": {
    "enabled": true,
    "path": "logs/logs.txt",
    "interval": "day"
  },
  "seq": {
    "enabled": true,
    "url": "http://localhost:5341",
    "token": "secret"
  }
}

Table of Contents

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published