Skip to content

skomis-mm/serilog-sinks-file

 
 

Repository files navigation

Serilog.Sinks.File Build status Travis build 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: By default only one process may use a log file at a given time. See Shared log files below if multi-process logging is required.

<appSettings> configuration

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

<add key="serilog:using:File" value="Serilog.Sinks.File" />
<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.

Shared log files

Multiple processes can concurrently write to the same log file if the shared parameter is set to true:

    .WriteTo.File("log.txt", shared: true)

Performance

By default, the file sink will flush each event written through it to disk. To improve write performance, specifying buffered: true will permit the underlying stream to buffer writes.

The Serilog.Sinks.Async package can be used to wrap the file sink and perform all disk accss on a background worker thread.

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

About

The file sink for Serilog

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.6%
  • PowerShell 1.7%
  • Shell 0.7%