Код: Выделить всё
var builder = Host.CreateDefaultBuilder(args);
Я могу внедрить ILogger или ILoggingFactory в свой класс и писать всем поставщикам журналов с помощью функции ILogger.Log.
/>
Код: Выделить всё
public class BusinessLogic
{
private IHostEnvironment _env;
private ILogger _logger;
public BusinessLogic(
IHostEnvironment env,
ILoggerFactory loggerFactor)
{
_env = env;
_logger = loggerFactor.CreateLogger();
}
public void Run()
{
foreach (var level in Enum.GetValues())
{
_logger.Log(level, $"Test logging at level {level}.");
}
Console.WriteLine("Hello, World! Press any key...");
Console.ReadLine();
}
}
Код: Выделить всё
{
"Logging":
{
//Settings for the windows event log logging provider
"EventLog":
{
"LogName": "Application",
"SourceName": "MySource",
"LogLevel":
{
"Default": "Trace"
}
}
}
}
Код: Выделить всё
var builder = Host.CreateDefaultBuilder(args);
builder.ConfigureAppConfiguration((context, builder) =>
{
var eventLogConfiguration = context.Configuration.GetSection("Logging:EventLog").Get();
builder.AddEventLog(eventLogConfiguration);
});
Код: Выделить всё
var builder = Host.CreateDefaultBuilder(args);
builder.ConfigureAppConfiguration((context, builder) =>
{
builder.ClearProviders();
var eventLogConfiguration = context.Configuration.GetSection("Logging:EventLog").Get();
builder.AddEventLog(eventLogConfiguration);
});
Подробнее здесь: https://stackoverflow.com/questions/745 ... -json-file
Мобильная версия