Skip to content

A simple wrapper for Serilog which provides multiple types of tracking.

Notifications You must be signed in to change notification settings

vish9812/serilog-wrapper

Repository files navigation

Serilog Wrapper

A simple wrapper for Serilog.

It offers 5 types of logging

  • Usage(Audit) - Tracks web requests
  • Error - Provides global error handler
  • Info - Logs general messages
  • Diagnostic - Logs conditional/debugging messages
  • Performance - Tracks timings of web requests

Update Appsettings.json

"Serilog": {
    "SelfLog": true,
    "Model": {
      "Product": "My Product XYZ",
      "LogSession": true
    },
    "Modules": {
      "Usage": true,
      "Error": true,
      "Info": true,
      "Diagnostic": true,
      "Performance": true
    },
    "Sql": {
      "SchemaName": "dbo",
      "AutoCreateSqlTable": false,
      "RestrictedToMinimumLevel": 1, //Verbose-0, Debug-1, Information-2, Warning-3, Error-4, Fatal-5
      "BatchPostingLimit": 100,
      "Period": "0.00:00:10",
      "TableName": {
        "Usage": "UsageLogs",
        "Error": "ErrorLogs",
        "Info": "InfoLogs",
        "Diagnostic": "DiagnosticLogs",
        "Performance": "PerformanceLogs"
      }
    }
  }

Usage

  • Register Logging dependecies

In Startup.cs -> ConfigureServices Method

services.RegisterLogger();
  • Register Exception Logger

In Startup.cs -> Configure Method

//for MVC
app.UseMvcExceptionLogger();

//for API
app.UseAPIExceptionLogger();
  • Register Usage and Performance Global Filters

In Startup.cs -> ConfigureServices Method

services.AddMvc(options =>
{
    options.Filters.Add<TrackUsageFilter>();
    options.Filters.Add<TrackPerformanceFilter>();
})
  • To use any of the loggers directly, just inject the ILogger.

About

A simple wrapper for Serilog which provides multiple types of tracking.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages