如何使用serilog身份验证在kibana中将日志设置为ELK [英] How to set logs to ELK in kibana with authentication using serilog
本文介绍了如何使用serilog身份验证在kibana中将日志设置为ELK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经设置了代码示例,但是无法使用serilog登录到带有验证的kibana。
在这里,我已经附加了我的代码,请对其进行更正。
I have set an example of my code but I'm not able to logs in kibana with authentication using serilog. Here, I have attached my code please correct it.
Log.Logger = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("myurl:9200"))
{
IndexFormat = "ChargeMasterlog-{yyyy.MM.dd}",
ModifyConnectionSettings = x => x.BasicAuthentication("username", "password"),
}).CreateLogger();
Log.Information("Hello, Serilog!");
推荐答案
第一步:安装此NuGet软件包 Serilog.Sinks。 Elasticsearch
Step1: Install this NuGet package "Serilog.Sinks.Elasticsearch"
Step2:将其添加到App.config或Web.config
Step2: Add this in App.config or Web.config
<appSettings>
<add key="elasticsearchURL" value="your_URL" />
<add key="elasticsearchuserName" value="your_Username" />
<add key="elasticsearchpassword" value="your_Password" />
<add key="elasticsearchIndex" value="indexname-{0:yyyy.MM.dd}" /> <!-- make sure index start with small letter -->
</appSettings>
Step3:将其添加到program.cs的main()或Global.asax的Application_Start()
Step3: Add this in program.cs in main() OR Global.asax in Application_Start()
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(ConfigurationManager.AppSettings["elasticsearchURL"]))
{
AutoRegisterTemplate = true,
ModifyConnectionSettings = x => x.BasicAuthentication(ConfigurationManager.AppSettings["elasticsearchuserName"], ConfigurationManager.AppSettings["elasticsearchpassword"]),
IndexFormat = ConfigurationManager.AppSettings["elasticsearchIndex"]
})
.CreateLogger();
Step4:通过添加
Step4: Log events where you want by adding
using Serilog;
Log.Error("Your_Message", ex);
Log.CloseAndFlush();
这篇关于如何使用serilog身份验证在kibana中将日志设置为ELK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文