Код: Выделить всё
_ = pServiceCollection.AddSerilog((serviceProvider, loggerConfiguration)
=> loggerConfiguration.ReadFrom.Configuration(pConfiguration)
.ReadFrom.Services(serviceProvider)
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: LogMessageTemplate,
formatProvider: CultureInfo.InvariantCulture)
.WriteTo.File(path: logFilePath,
outputTemplate: LogMessageTemplate,
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 30,
formatProvider: CultureInfo.InvariantCulture)
.WriteTo.EventLog(source: CommonConstants.ProductName,
manageEventSource: true,
restrictedToMinimumLevel: LogEventLevel.Warning,
formatProvider: CultureInfo.InvariantCulture));
Но есть один тип информационного уровня запись, которую я хочу внести в журнал событий.
Я попробовал добавить это ограничение (
Код: Выделить всё
Filter.ByIncludingOnly
Код: Выделить всё
.WriteTo.File(path: logFilePath,
outputTemplate: LogMessageTemplate,
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 30,
formatProvider: CultureInfo.InvariantCulture)
.WriteTo.EventLog(source: CommonConstants.ProductName,
manageEventSource: true,
restrictedToMinimumLevel: LogEventLevel.Warning,
formatProvider: CultureInfo.InvariantCulture)
.Filter.ByIncludingOnly(e =>
(e.Level == LogEventLevel.Information &&
(e.Properties.ContainsKey("SourceContext") &&
e.Properties["SourceContext"].ToString().Contains(CommonConstants.ForceLoggingToEventLogCategory))) ||
e.Level >= LogEventLevel.Warning));
Код: Выделить всё
var forcelogger = app.Services.GetService()!.CreateLogger(CommonConstants.ForceLoggingToEventLogCategory);
forcelogger.LogInformation("force hallo Welt");
Подробнее здесь: https://stackoverflow.com/questions/791 ... -the-sever