Skip to content

serilog/serilog-sinks-file

Repository files navigation

Serilog.Sinks.File Build status NuGet Version Documentation Join the chat at https://gitter.im/serilog/serilog

Writes Serilog events to a text file.

var log = new LoggerConfiguration()
    .WriteTo.File("log.txt")
    .CreateLogger();

To avoid bringing down apps with runaway disk usage the file sink limits file size to 1GB by default. The limit can be increased or removed using the fileSizeLimitBytes parameter.

    .WriteTo.File("log.txt", fileSizeLimitBytes: null)

Important: Only one process may write to a log file at a given time. For multi-process scenarios, either use separate files or one of the non-file-based sinks.

<appSettings> configuration

The sink can be configured in XML app-settings format if the Serilog.Settings.AppSettings package is in use:

<add key="serilog:write-to:File.path" value="log.txt" />
<add key="serilog:write-to:File.fileSizeLimitBytes" value="" />

JSON formatting

To emit JSON, rather than plain text, a formatter can be specified:

    .WriteTo.File(new JsonFormatter(), "log.txt")

To configure an alternative formatter in XML <appSettings>, specify the formatter's assembly-qualified type name as the setting value.

Copyright © 2016 Serilog Contributors - Provided under the Apache License, Version 2.0.

About

Write Serilog events to files in text and JSON formats, optionally rolling on time or size

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published