. Net Core's log mode: Serilog+kibana

Source: Internet
Author: User
Tags kibana

Objective

Serilog, support objects, the log data serialized into JSON, easy to use, easily expand. Github:https://github.com/handsomeyao77/serilog-sinks-elasticsearch

Reading the configuration file

The configuration file is divided into app. Config and Appsetting.json two types.
Read Appsettings.json, primarily web app types, first inject the JSON file when the service starts:

Read configuration:

To configure App. Config, the highlighted part is the necessary key:

Read configuration:

Of course, sometimes you can hard code, and here's a way to share:

Common Types of Serilog

1.Information.

2.Debug.

3.Error.

Because Logeventbase as a base class, you can inherit and expand.

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;}

Based on business development:

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 is more practical, and viewing log in Kibana can save a lot of time as a filtering condition.

How to use 1.Information

2.Error

Kibana

Open the Kibana homepage and select the corresponding template, which can be said to be a very useful log tool. You can follow the log time, or enter the query criteria:

Alternatively, you can quickly locate the target by following logeventtype:

. Net Core's log mode: Serilog+kibana

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.