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.
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="" />
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.