serilog-sinks-elasticsearch
serilog-sinks-elasticsearch copied to clipboard
Why Serilog logs shown in Docker logs instead of Elastic Search?
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");
I m not sure what you mean with shown in container log. Can you explain more? Running inside or outside a docker container should not matter. Either it outputs to the standard out (which is captured to the console or the docker log stream) or it sends it to ES (as long as your docker container can reach the ES instance).