【问题标题】:Change elasticsearch serilog sink http content header更改 elasticsearch serilog sink http 内容标头
【发布时间】:2019-01-20 09:05:16
【问题描述】:

我正在尝试使用 serilog elasticsearch sink 将一些日志写入 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 中。 是我做错了什么,还是无法配置,或者我需要更改服务器中的某些内容?

【问题讨论】:

    标签: c# elasticsearch kibana serilog


    【解决方案1】:

    我希望下面的代码有助于找出问题所在

    ModifyConnectionSettings = x => x.OnRequestCompleted(ELKReqCompleted);
    
     void ELKReqCompleted(IApiCallDetails apiCallDetails)
            {
                //apiCallDetails.AuditTrail
                //apiCallDetails.DebugInformation
    
            }
    

    【讨论】:

      猜你喜欢
      • 2013-10-01
      • 1970-01-01
      • 2019-07-06
      • 2012-10-31
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      • 1970-01-01
      • 2016-11-19
      相关资源
      最近更新 更多