Logging

Logging TD Web API.

Cấu hình trong src/Host/Configurations/logger.json.

Console

Mặc định sử dụng Console Logging. Package sử dụng - Serilog.Sinks.Console

builder.Host.UseSerilog((_, config) =>
{
    config.WriteTo.Console()
    .ReadFrom.Configuration(builder.Configuration);
});

File

Log đuợc ghi dưới định dạng JSON và lưu trong file Package sử dụng - Serilog.Sinks.File

"Name": "File",
"Args": {
  "path": "Logs/logs.json",
  "formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
  "rollingInterval": "Day",
  "restrictedToMinimumLevel": "Information",
  "retainedFileCountLimit": 5
}

SEQ

Package sử dụng - Serilog.Sinks.Seq

Cài đặt SEQ trước nếu có ý định sử dụng

"Name": "Seq",
"Args": {
  "serverUrl": "http://localhost:5341"
}

Điều kiện: đã cài Kibana và ElasticSearch (có thể dùng docker)

Mặc định

  • Kibana runs on port 5601 - http://localhost:5601
  • Elastic Search runs on port 9200 - http://localhost:9200

Package sử dụng - Serilog.Sinks.Elasticsearch

"Name": "Elasticsearch",
"Args": {
  "nodeUris": "http://localhost:9200;",
  "indexFormat": "DN.WebApi-logs-{0:yyyy.MM}",
  "numberOfShards": 2,
  "numberOfReplicas": 1,
  "restrictedToMinimumLevel": "Information"
}

Like TDWebAPI? ❤️

Here is what you can do to show your support!

Buy me a Coffee ☕