docker - Serilog 与 .net 核心 web api 2.2
问题描述
我正在尝试使用ElasticSearchSink
for Serilog
。我有docker-compose
文件要启动ElasticSearch
,Kibana
并且.NET Core 2.2 Web API
.
这是inConfigure
中的代码Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
var elasticUri = Configuration["ElasticConfiguration:Uri"];
var logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticUri))
{
AutoRegisterTemplate = true
});
loggerFactory.AddSerilog();
Log.Logger = logger.CreateLogger();
app.UseMvc();
}
appsettings.json
是
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"AllowedHosts": "*",
"ElasticConfiguration": {
"Uri": "http://localhost:9200/"
}
}
我可以击中localhost:9200
并且Kibana
发射也很好。但是里面没有数据Kibana
。我没有看到任何错误,但我期待ES
and中有一些数据Kibana
。
控制器类是:
public class AuthenticationController : ControllerBase
{
private readonly ILogger<AuthenticationController> _logger;
public AuthenticationController(ILogger<AuthenticationController> logger)
{
_logger = logger;
}
[HttpPost]
[Route("token")]
public async Task<IActionResult> ValidateToken([FromBody] AuthenticateRequest request)
{
_logger.LogInformation($"ValidateToken: request received with {request}");
return Ok(new AuthenticateRespose
{
Token = "testing", Duration = 0
});
}
}
Postman
我可以从运行或仅使用in 进行docker-compose
调试来达到该端点。Docker
VS
我错过了什么?
解决方案
你确定这http://localhost:9200/
是正确的吗?不同的 Docker 容器是否在共享网络接口上运行?如果不是,您可能应该尝试将其更改为您在 Docker 撰写文件http://<service name>:9200/
中service name
为 Serilog 容器提供的名称。
推荐阅读
- python - Flask App 未使用 VS Code 进行调试
- azure - Azure DevOps Pipeline:排除 PR 的路径
- javascript - 使用 Google OAuth 2.0 禁用自动登录
- javascript - 如何将 args 放入 onreadystatechange 函数中
- discord.js - 在特定时间过去后计算对消息的反应
- javascript - 如何在js中访问动态变量?
- javascript - Vimeo 播放器 - 如何取消静音和从屏幕上删除所有按钮(现场活动)
- html - 在网格实验期间我无法删除的额外边距
- flutter - 使用 HH:MM:SS 格式将秒数四舍五入到最接近的分钟
- javascript - 在javascript中使用reduce和recursion来展平嵌套数组