Serilog配置

serilog-sinks-file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="serilog:using:File" value="Serilog.Sinks.File" />
    <add key="serilog:write-to:File.path" value="log\log.txt" />
    <add key="serilog:write-to:File.rollOnFileSizeLimit" value="true" />
    <add key="serilog:write-to:File.fileSizeLimitBytes" value="3072" />
    <add key="serilog:write-to:File.shared" value="true" />
    <add key="serilog:write-to:File.retainedFileCountLimit" value="null" />
  </appSettings>
</configuration>

 https://github.com/serilog/serilog-sinks-file/blob/dev/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs#L180

void ApplyRetentionPolicy(string currentFilePath, DateTime now)
        {
            if (_retainedFileCountLimit == null && _retainedFileTimeLimit == null) return;
         }

 

Serilog配置不指定配置文件的路径

https://github.com/serilog/serilog-settings-appsettings/blob/dev/src/Serilog.Settings.AppSettings/Settings/AppSettings/AppSettingsSettings.cs#L56

会直接从程序的默认配置文件中app.config加载appsettings结点下的配置

  settings = ConfigurationManager.AppSettings.AllKeys
                    .Select(k => new KeyValuePair<string, string>(k, ConfigurationManager.AppSettings[k]));
_settingPrefix = settingPrefix == null ? "serilog:" : $"{settingPrefix}:serilog:";

 

 var pairs = settings
                .Where(k => k.Key.StartsWith(_settingPrefix))
                .Select(k => new KeyValuePair<string, string>(
                    k.Key.Substring(_settingPrefix.Length),
                    Environment.ExpandEnvironmentVariables(k.Value)));

            loggerConfiguration.ReadFrom.KeyValuePairs(pairs);

 

posted @ 2020-07-14 10:42  ChuckLu  阅读(2451)  评论(0编辑  收藏  举报