如何使用 dotnet Logging 将 Json 对象存储到 ELK

How store Json Object to ELK using dotnet Logging

如何使用 dotnet 日志记录接口存储 Json 对象。我正在使用 Serilog 作为提供者。

使用此代码,我在检查日志时从未看到 "myObject":

public CommandResult Example(MyObject myObject)
{
        try
        {
             logger.LogInformation("myObject is : ", myObject); // <== log my object as json
         }
         catch (System.Exception ex)
         {
             logger.LogError(ex, "error");
         }

         return null;
}

如何记录 args 对象?:

有可能还是我应该使用其他方式?

----- 编辑 2018-10-22 -----

当我使用 属性 {@属性} 登录时,我可以看到关于 Kibana 的信息。 但我只保存原始 属性

工作

logger.LogInformation("SendMessageToFrontEnd {@user} {@message} {@sendDate}", Model.Owner.Id, "Test", messages.SentDate);

不工作

class myObject
{
  [JsonProperty("dataInt")]
  public int DataInt { get; set; }
  [JsonProperty("name")]
  public string Name { get; set; }
}

...

var test = new myObject() { DataInt = 123, Name = "test" };
logger.LogInformation("SendMessageToFrontEnd {@user} {@message} {@sendDate}", Model.Owner.Id, test, messages.SentDate);

如何记录JSON对象?

经过一些调查,我修复了我的错误(不明白为什么)。

但是当您登录到 ELK 时,消息 字段似乎已被保留。

// NOT WORK
logger.LogInformation("SendMessageToFrontEnd {@user} {@message} {@sendDate}", Model.Owner.Id, test, messages.SentDate);

// WORK
logger.LogInformation("SendMessageToFrontEnd {@user} {@messageSent} {@sendDate}", Model.Owner.Id, test, messages.SentDate);

本.