Serilog,一个文件接收器写入,一个是留下一个空白文件

问题描述 投票:0回答:1

所以我有一个简单的方法为我制作记录器实例。

它如下

protected ILogger GetIndividualLogger(ILogger parentLogger, LogEventLevel minimumLevel, string RootDir, string Type, string Name, bool shouldBuffer, bool shouldBeShared, TimeSpan flushToDiskInterval)
{
    var LogAllFile = $"{RootDir}{Path.DirectorySeparatorChar}{Name}{Path.DirectorySeparatorChar}RAL-{Type}-{Name}-.log";
    var LogWarningFile = $"{RootDir}{Path.DirectorySeparatorChar}{Name}{Path.DirectorySeparatorChar}Warnings{Path.DirectorySeparatorChar}RAL-{Type}-{Name}-.log";

    ILogger logger = new LoggerConfiguration()
        .MinimumLevel.Is(minimumLevel)
        .Enrich.WithDemystifiedStackTraces()
        .WriteTo.Async(a => a.Logger(parentLogger))
        .WriteTo.Async(a => a.File(LogAllFile, outputTemplate: SerilogHereHelper.TemplateForHere, rollingInterval: RollingInterval.Day, buffered: shouldBuffer, shared: shouldBeShared))
        .WriteTo.Async(a => a.File(LogWarningFile, restrictedToMinimumLevel: LogEventLevel.Warning, outputTemplate: SerilogHereHelper.TemplateForHere, rollingInterval: RollingInterval.Day, buffered: shouldBuffer, shared: shouldBeShared, flushToDiskInterval: flushToDiskInterval))
        .CreateLogger();
    return logger;
}

以下是对GetIndividualLogger的示例调用

GetIndividualLogger(parentLogger: mainLogger, minimumLevel: LogEventLevel.Information, RootDir: _stackLightLogPath, Type: "Stack Light", Name: "Stack Light 1", shouldBuffer: true, shouldBeShared: false, flushToDiskInterval: TimeSpan.FromSecond(2))

警告级别接收器将写入,但是另一个接收器(通常设置为调试或信息)将创建一个空文件但从不向其添加任何条目。

我希望这两个文件都具有所有警告级别条目或更高级别。我希望“LogAllFile”的所有条目都达到或超过最低级别,但它是空白的。

我的记录器配置有问题吗?或者我的问题在别的地方?

serilog
1个回答
0
投票

所以这个问题的答案很愚蠢。警报日志每2秒刷新一次到磁盘,但是主日志文件不是那么我需要做的就是为flushToDiskInterval传递一个值

.WriteTo.Async(a => a.File(LogAllFile, outputTemplate: SerilogHereHelper.TemplateForHere, rollingInterval: RollingInterval.Day, buffered: shouldBuffer, shared: shouldBeShared, flushToDiskInterval: flushToDiskInterval))
© www.soinside.com 2019 - 2024. All rights reserved.