[英]Elasticsearch, Kibana, dotnet core and docker
I have my dotnet core application set up to use SeriLog
which logs to an ElasticSearch Sink
.我将我的 dotnet 核心应用程序设置为使用SeriLog
,它记录到ElasticSearch Sink
。 When running my dotnet core app locally with ElasticSearch
and Kibana
I have two separate containers I'm able to log stuff from my application to Elastic and I'm also able to see these log messages in Kibana
.当使用ElasticSearch
和Kibana
在本地运行我的 dotnet 核心应用程序时,我有两个单独的容器,我可以将应用程序中的内容记录到 Elastic,我还可以在Kibana
看到这些日志消息。
When I include my dotnet core application in the docker-compose.yml
file, navigating to the endpoint where the app is located, I expect it to log several messages to Elasticsearch
, but it doesn't.当我在docker-compose.yml
文件中包含我的 dotnet 核心应用程序,导航到应用程序所在的端点时,我希望它会向Elasticsearch
记录几条消息,但它没有。 I suspect that my application doesn't understand how to communicate with Elasticsearch
when it's being containerized.我怀疑我的应用程序在容器化时不了解如何与Elasticsearch
通信。 My docker-compose.yml
looks like this:我docker-compose.yml
看起来像这样:
version: '3.0'版本:'3.0'
services:
db:
image: mysql:5.7
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: chtr
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbuserpassword
volumes:
- dbdata:/var/lib/mysql
- ./_MySQL_Init_Script:/docker-entrypoint-initdb.d
restart: always
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
container_name: elasticsearch
ports:
- "9200:9200"
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
kibana:
image: docker.elastic.co/kibana/kibana:6.2.4
container_name: kibana
ports:
- "5601:5601"
depends_on:
- elasticsearch
chtr.server:
depends_on:
- db
- kibana
image: trebias/chtr.server
build:
context: .
ports:
- "8080:80"
- "56:5601"
volumes:
dbdata:
elasticsearch-data:
chtr.server
is my image being pull from my docker hub. chtr.server
是我从我的chtr.server
集线器中提取的图像。
Over to the appsettings.json
within my dotnet core application: appsettings.json
我的 dotnet 核心应用程序中的appsettings.json
:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
}
},
"ElasticConfiguration": {
"Uri": "http://[::]:9200/"
}
}
Where I create the Logger like this in my Startup.cs
file:我在Startup.cs
文件中创建这样的 Logger:
var elasticSearch = Configuration["ElasticConfiguration:Uri"];
Log.Logger = new LoggerConfiguration().Enrich.FromLogContext().WriteTo.Elasticsearch(new ElasticsearchSinkOptions(
new Uri(elasticSearch)) { AutoRegisterTemplate = true }).CreateLogger();
Like I said at the beginning of this post;就像我在这篇文章开头所说的那样; It works when I run Kibana
and Elasticsearch
in containers and my app locally, but not when all three apps are in containers.当我在容器和本地应用程序中运行Kibana
和Elasticsearch
时,它可以工作,但当所有三个应用程序都在容器中时,它不起作用。
Any suggestions?有什么建议?
The service is running under container that's why you should write your log using the container name like bellow:该服务在容器下运行,这就是为什么您应该使用如下容器名称编写日志:
Appsettings.Development.json: Appsettings.Development.json:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
}
},
"ElasticConfiguration": {
"Uri": "http://elasticsearch:9200/"
}
}
You can find here a full example showing how to setup Serilog, Seq, elasticsearch and kibana to work together under Docker containers solution.您可以在此处找到一个完整示例,该示例展示了如何设置 Serilog、Seq、elasticsearch 和 kibana 以在 Docker 容器解决方案下协同工作。
structure logging with serilog seq and elastic search under docker 使用 serilog seq 和 docker 下的弹性搜索进行结构日志记录
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.