Skip to content

SeriLog

Kota edited this page Sep 21, 2018 · 13 revisions
  • Serilog provides diagnostic logging to files, the console, and elsewhere

Installation - Nuget

  • SeriLog: Basic configurations of SeriLog

  • Sinks: Which helps in storing the logs into specific type of storage systems

    • Serilog.Sinks.Console
    • Serilog.Sinks.ColoredConsole
    • Serilog.Sinks.File
    • Serilog.Sinks.RollingFile
  • Basic Settings

var template = "{Timestamp:yyyy-MMM-dd HH:mm::ss} [{Level}] {Message}{NewLine}{Exception}";
var _logger = new LoggerConfiguration()
                            .WriteTo.Console()
                            .WriteTo.ColoredConsole(Serilog.Events.LogEventLevel.Verbose, outputTemplate: template)
                            .WriteTo.File("log.txt")
                            .WriteTo.RollingFile("rollinglogfile.txt", retainedFileCountLimit: 2)
                            .CreateLogger();

Log.Logger = _logger;
Log.Logger.Information("Log Message");

Logging Structured Data

  • Scalar Data: Boolean, Int (byte <=> decimal), String, DateTime, Others (GUID, URI, nullables)
  • Collections, Objects, Dictionary<key, value> (key must be Scalar),

Clone this wiki locally