简体   繁体   English

日志属性未记录在Serilog中

[英]Log properties not recording in Serilog

For exmple, I have function doSomething(string a, string b, string c) . 例如,我有函数doSomething(string a, string b, string c) And I want to log function executing. 而且我想记录功能执行情况。 I want do something like this: 我想做这样的事情:

Logger.Debug("Method doSomething executed", a, b, c)

to avoid writing parameters in message beacause strings can be very long. 避免在消息中写入参数,因为字符串可能很长。 This functionality is similar to the .Enrich.WithProperty("PropertyName", Value) . 此功能类似于.Enrich.WithProperty("PropertyName", Value) But i can't do this in Logger constructor. 但是我无法在Logger构造函数中执行此操作。 Logs writes to SEQ . 日志写入SEQ

ForContext() can do this: ForContext()可以做到这一点:

var enriched = Log.ForContext("A", a)
                  .ForContext("B", b)
                  .ForContext("C", c);

enriched.Debug("Method doSomething executed");

All events logged through enriched will have the properties A , B and C attached. 通过enriched记录的所有事件将附加属性ABC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM