This repository was archived by the owner on Jun 1, 2024. It is now read-only.
This repository was archived by the owner on Jun 1, 2024. It is now read-only.
Why Serilog logs shown in Docker logs instead of Elastic Search? #302
Open
Description
I have .net core app running in docker container , also I have another containers have elasticsearch port:9201 and kibana port:5602. When I run sample .net core app on local, logs directly saved on elasticsearch , but in another dockerized .net core app , the same serilog logs are shown in docker container logs. I added the sample code. For any help I appreciated really need this help. appsettings.json(in same way docker and developement):
"Logging": {
"LogLevel": {
"Default": "Warning",
"System": "Warning",
"Microsoft": "Warning"
}}, "ElasticConfiguration": {
"Uri": "http://localhost:9001" },"AllowedHosts": "*"
startup.cs:
var builder = new ConfigurationBuilder()
.SetBasePath(hostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{hostingEnvironment.EnvironmentName}.json", reloadOnChange: true, optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
var elasticUri = Configuration["ElasticConfiguration:Uri"];
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticUri))
{
AutoRegisterTemplate = true,
})
.CreateLogger();
Configure :
loggerFactory.AddSerilog();
And in controller :
Logger<Manager> _logger;
public Manager(ILogger<Manager> logger)
{ _logger = logger;}
}
_logger.LogWarning("Stream Has Started");