我正在尝试使用serilog elasticsearch接收器将一些日志写入kibana。
根据规范here
内容应设置为application/x-ndjson
,并且由于没有用于设置内容类型的特定选项(我尝试使用GlobalHeaders
进行设置),但它没有任何作用,并且设置为json。
我已将示例应用程序更改为以下内容:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console(theme: SystemConsoleTheme.Literate)
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://elastic:changeme@localhost:9200")) // for the docker-compose implementation
{
ModifyConnectionSettings =
x => x.GlobalHeaders(new NameValueCollection { { "Content-Type", "application/x-ndjson" } }),
BufferBaseFilename = "Text.txt",
Period = TimeSpan.FromSeconds(10),
AutoRegisterTemplate = true,
//BufferBaseFilename = "./buffer",
RegisterTemplateFailure = RegisterTemplateRecovery.IndexAnyway,
FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate),
EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog |
EmitEventFailureHandling.WriteToFailureSink |
EmitEventFailureHandling.RaiseCallback,
FailureSink = new FileSink("./failures.txt", new JsonFormatter(), null)
})
.CreateLogger();
// Enable the selflog output
SelfLog.Enable(Console.Error);
Log.Information("Hello, world!");
int a = 10, b = 0;
try {
Log.Debug("Dividing {A} by {B}", a, b);
Console.WriteLine(a / b);
} catch (Exception ex) {
Log.Error(ex, "Something went wrong");
}
for (int i = 0; i < 10; i++) {
Log.Error(new Exception($"Test error {i}"), "Test error {Error}", "TEst message");
}
api调用不会返回错误,但是日志在kibana中不存在。 我是在做错什么,还是无法配置,或者我需要在服务器中更改某些东西?
答案 0 :(得分:0)
我希望以下代码有助于找出问题所在
ModifyConnectionSettings = x => x.OnRequestCompleted(ELKReqCompleted);
void ELKReqCompleted(IApiCallDetails apiCallDetails)
{
//apiCallDetails.AuditTrail
//apiCallDetails.DebugInformation
}