代码语言:javascript复制
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!--enumeration: Verbose, Debug, Information, Warning, Error, Fatal.-->
<add key="serilog:minimum-level" value="Debug" />
<add key="serilog:using:Console" value="Serilog.Sinks.Console" />
<add key="serilog:write-to:Console"/>
<!--<add key="serilog:write-to:Console.theme" value="Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console" />-->
<add key="serilog:write-to:Console.outputTemplate" value="[{Timestamp:HH:mm:ss.fff} {Level:u3}]{Message:lj}{NewLine}{Exception}" />
<add key="serilog:write-to:Console.restrictedToMinimumLevel" value="Information"/>
<add key="serilog:using:File" value="Serilog.Sinks.File" />
<add key="serilog:write-to:File.path" value="LOG/Serilog.txt" />
<add key="serilog:write-to:File.retainedFileCountLimit" value="10" />
<add key="serilog:write-to:File.RollingInterval" value="Day" />
<add key="serilog:write-to:File.restrictedToMinimumLevel" value="Warning" />
<add key="serilog:write-to:File.rollOnFileSizeLimit" value="true" />
<add key="serilog:write-to:File.fileSizeLimitBytes" value="50000" />
<!--<add key="serilog:using:Udp" value="Serilog.Sinks.Udp" />
<add key="serilog:write-to:Udp" />
<add key="serilog:write-to:Udp.restrictedToMinimumLevel" value="Debug" />
<add key="serilog:write-to:Udp.remoteAddress" value="localhost" />
<add key="serilog:write-to:Udp.remotePort" value="7071" />
<add key="serilog:write-to:Udp.family" value="InterNetwork" />-->
</appSettings>
</configuration>
代码语言:javascript复制using Serilog;
public static class LogHelper
{
public static ILogger log = new LoggerConfiguration()
.ReadFrom.AppSettings().CreateLogger();
}
以上是app.config配置文件和代码。
运行