Код: Выделить всё
internal class ConfigLogger
{
public ConfigLogger()
{
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.WriteTo.Debug()
.WriteTo.Console()
.WriteTo.Elasticsearch(ConfigureElasticSink(ConfigUtility.Configuration, ConfigUtility.CurrentEnvironment))
.Enrich.WithProperty("Environment", ConfigUtility.CurrentEnvironment)
.ReadFrom.Configuration(ConfigUtility.Configuration)
.CreateLogger();
}
ElasticsearchSinkOptions ConfigureElasticSink(IConfigurationRoot configuration, string environment)
{
return new ElasticsearchSinkOptions(new Uri(ConfigUtility.GetValue("ElasticSearchConfiguration:Uri")))
{
AutoRegisterTemplate = true,
IndexFormat = $"{Assembly.GetExecutingAssembly().GetName().Name.ToLower().Replace(".", "_")}-{environment.ToLower()}-{DateTime.UtcNow:yyyy-mm}",
BatchAction = ElasticOpType.Create,
NumberOfReplicas = 1,
NumberOfShards = 2,
ModifyConnectionSettings = x => x.BasicAuthentication("", ""),
};
}
}
Код: Выделить всё
services.AddLogging(builder =>
{
builder.AddSerilog(Log.Logger, true);
});
логгер конфигурации инициируется в основной функции.
Но основная проблема заключается в том, что всякий раз, когда я делаю журнал терминала elasticsearch. Но журналы в индексе не ведутся.
Код: Выделить всё
[2024-04-12T09:55:15,326][INFO ][o.e.c.m.MetadataIndexTemplateService] updating index template [serilog-events-template] for index patterns [neo-fleet-manager-development-2024-25]
Код: Выделить всё
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Verbose",
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
},
"ElasticSearchConfiguration": {
"Uri": "http://localhost:9200",
"username": "",
"password": "",
"DefaultIndex": ""
},
"AllowedHosts": "*"
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... sticsearch
Мобильная версия