如何使用serilog身份验证在kibana中将日志设置为ELK
我已经设置了代码示例,但是无法使用serilog登录到带有验证的kibana。在这里,我已附上我的代码,请对其进行更正。
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!");
回答:
步骤1:安装此NuGet软件包“ Serilog.Sinks.Elasticsearch”
步骤2:在App.config或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>
步骤3:在main()的program.cs或Application_Start()的Global.asax中添加它
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();
步骤4:通过添加将日志记录到所需的位置
using Serilog; Log.Error("Your_Message", ex);
Log.CloseAndFlush();
以上是 如何使用serilog身份验证在kibana中将日志设置为ELK 的全部内容, 来源链接: utcz.com/qa/412750.html