skbkontur/serilog

Name: serilog

Owner: Kontur

Description: Simple .NET logging with fully-structured events

Forked from: serilog/serilog

Created: 2017-03-06 14:41:19.0

Updated: 2017-03-06 14:41:21.0

Pushed: 2017-04-06 02:59:58.0

Homepage: https://serilog.net

Size: 75184

Language: C#

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Serilog Build status NuGet Version Rager Releases Join the chat at https://gitter.im/serilog/serilog Stack Overflow

Serilog is a diagnostic logging library for .NET applications. It is easy to set up, has a clean API, and runs on all recent .NET platforms. While it's useful even in the simplest applications, Serilog's support for structured logging shines when instrumenting complex, distributed, and asynchronous applications and systems.

Serilog

Like many other libraries for .NET, Serilog provides diagnostic logging to files, the console, and many other outputs.

log = new LoggerConfiguration()
.WriteTo.LiterateConsole()
.WriteTo.RollingFile("log-{Date}.txt")
.CreateLogger();

Information("Hello, Serilog!");

Unlike other logging libraries, Serilog is built from the ground up to record structured event data.

position = new { Latitude = 25, Longitude = 134 };
elapsedMs = 34;

Information("Processed {@Position} in {Elapsed} ms.", position, elapsedMs);

Serilog uses message templates, a simple DSL that extends .NET format strings with named as well as positional parameters. Instead of formatting events immediately into text, Serilog captures the values associated with each named parameter.

The example above records two properties, Position and Elapsed, in the log event. The @ operator in front of Position tells Serilog to serialize the object passed in, rather than convert it using ToString(). Serilog's deep and rich support for structured event data opens up a huge range of diagnostic possibilities not available when using traditional loggers.

Rendered into JSON format for example, these properties appear alongside the timestamp, level, and message like:

sition": {"Latitude": 25, "Longitude": 134}, "Elapsed": 34}

Back-ends that are capable of recording structured event data make log searches and analysis possible without log parsing or regular expressions.

Supporting structured data doesn't mean giving up text: when Serilog writes events to files or the console, the template and properties are rendered into friendly human-readable text just like a traditional logging library would produce:

4:22 [INF] Processed { Latitude: 25, Longitude: 134 } in 34 ms.

Upgrading from Serilog 1.x? Check out the 2.0 Upgrade Guide and Release Notes.

Features
Getting started

Serilog is installed from NuGet. To view log events, one or more sinks need to be installed as well, here we'll use the pretty-printing “literate” console sink, and a rolling file set:

all-Package Serilog
all-Package Serilog.Sinks.Literate
all-Package Serilog.Sinks.RollingFile

The simplest way to set up Serilog is using the static Log class. A LoggerConfiguration is used to create and assign the default logger.

ic class Program

public static void Main()
{
    Log.Logger = new LoggerConfiguration()
        .MinimumLevel.Information()
        .WriteTo.LiterateConsole()
        .WriteTo.RollingFile("log-{Date}.txt")
        .CreateLogger();
}

Find more, including a runnable example application, under the Getting Started topic in the documentation.

Getting help

To learn more about Serilog, check out the documentation - you'll find information there on the most common scenarios. If Serilog isn't working the way you expect, you may find the troubleshooting guide useful.

Serilog has an active and helpful community who are happy to help point you in the right direction or work through any issues you might encounter. You can get in touch via:

Contributing

Would you like to help make Serilog even better? We keep a list of issues that are approachable for newcomers under the up-for-grabs label. Before starting work on a pull request, we suggest commenting on, or raising, an issue on the issue tracker so that we can help and coordinate efforts.

Detailed build status

Branch | AppVeyor | Travis ————- | ————- |————- dev | Build status | Build Status master | Build status | Build Status

Serilog is copyright © 2013-2017 Serilog Contributors - Provided under the Apache License, Version 2.0. Needle and thread logo a derivative of work by Kenneth Appiah.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.