标签:mes .com base 前言 sink tps cep 选择 arc
Serilog,支持对象,把log数据序列化成Json,好用方便,容易拓展。Github: https://github.com/handsomeyao77/serilog-sinks-elasticsearch
配置文件分为App.config和appsetting.json两种。
读取appsettings.json,主要是Web app 类型,首先在服务启动时要注入json文件:
读取配置:
配置App.config,高亮部分是必要的key:
读取配置:
当然,有时候可以Hard code,这里分享一种方式:
1.Information.
2.Debug.
3.Error.
因为LogEventBase作为基类,可以继承拓展一下。
public class LogEventBase
{
[FieldOrder(0)]
public LogEventType EventType { get; set; }
[FieldOrder(1)]
public string Role { get; set; }
[FieldOrder(2)]
public string RoleInstance { get; set; }
[FieldOrder(3)]
public string Ip { get; set; }
[FieldOrder(4)]
public int Port { get; set; }
[FieldOrder(5)]
public DateTime Timestamp => DateTime.UtcNow;
[FieldOrder(6)]
public string Message { get; set; }
[FieldOrder(7)]
public IActivity Activity { get; set; }
[FieldOrder(8)]
public string EnvironmentName => Environment.MachineName;
}
根据业务拓展:
public class LatencyEvent : LogEventBase
{
[FieldOrder(9)]
public long Latency { get; set; }
[FieldOrder(10)]
public string SearchId { get; set; }
}
public class SearchEvent : LogEventBase
{
[FieldOrder(9)]
public string SearchId { get; set; }
[FieldOrder(10)]
public string SearchString { get; set; }
}
public class LuisEvent : LogEventBase
{
[FieldOrder(9)]
public LuisResult LuisResult { get; set; }
}
public class ExceptionEvent : LogEventBase
{
[FieldOrder(10)]
public Exception Exception { get; set; }
}
LogEventType是比较实用的,在kibana查看log是作为过滤条件能节省很多时间。
打开kibana主页,选择对应的template,可以说非常好用的log工具。可以按照log的时间,或者输入查询条件:
或者按照LogEventType,可以快速定位到target:
.Net Core的Log方式:Serilog+Kibana
标签:mes .com base 前言 sink tps cep 选择 arc
原文地址:https://www.cnblogs.com/shy-huang/p/9577735.html