.NET Serilog:如果多次调用,CreateLogger()现在抛出

时间:2018-05-11 06:45:31

标签: .net serilog

LoggerConfiguration loggerConfiguration = new LoggerConfiguration()
    .Enrich.With(new LogEnricher(User: userId, Name: Name));


 _Logger = loggerConfiguration
    .Enrich.WithProperty("TimeStamp", DateTime.UtcNow)
    .Enrich.WithProperty("Level", LogLevel.Error)
    .WriteTo.Email(
        connectionInfo: new EmailConnectionInfo()
        {
            EmailSubject = "",
            ToEmail = "",
            MailServer = "",
            NetworkCredentials = "",
            FromEmail = "",
            IsBodyHtml = true,
            EnableSsl = false
        },
        outputTemplate: outputTemplate,
        batchPostingLimit: 1,
        restrictedToMinimumLevel: LogEventLevel.Verbose
    ).CreateLogger();


 _Logger = loggerConfiguration
    .Enrich.WithProperty
    .Enrich.With(new LogEnricher(currentUser: userId, moduleName: moduleName))
    .Enrich.WithProperty("TimeStamp", DateTime.UtcNow)
    .Enrich.WithProperty("Level", logLevel)
    .WriteTo.MSSqlServer(
        connectionString: "ConnectionString",
        tableName: "someTable",
        columnOptions: columnOptions,
        restrictedToMinimumLevel: LogEventLevel.Error
    ).CreateLogger();

首先我想发送电子邮件错误&然后使用serilog CreateLogger()登录到DB。我正在使用相同的“LoggerConfiguration”实例来处理电子邮件和D B。这在Serilog 1.5中运行良好。更新到Serilog 2.3.0后,现在它抛出一个错误,说“CreateLogger()多次调用”

0 个答案:

没有答案