注:通过 using 的使用,可以在函数结束时自动移除属性 CallId。

代码示例:

public bool UsbRegRead(uint regAddr, ref uint regData)
{
  using (LogContext.PushProperty("CallId", Guid.NewGuid().ToString()))
  {
    Log.Information("UsbRegRead() <<");
    
    // ... 具体逻辑

    Log.Information("UsbRegRead() >>");

  }

}

 

 

参考如下:

Serilog 动态添加自定义属性

 

 

  

参考:官方教程

 

  

 

相关文章:

  • 2021-06-23
  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2021-11-16
猜你喜欢
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-25
  • 2021-12-14
相关资源
相似解决方案