-
Notifications
You must be signed in to change notification settings - Fork 5
/
DiagnosticLogger.cs
43 lines (37 loc) · 1.54 KB
/
DiagnosticLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Logging.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
namespace Logging
{
public class DiagnosticLogger : SeriLogger
{
private readonly IHttpContextAccessor contextAccessor;
protected override string TableName => configuration[$"{configTable}:Diagnostic"];
public DiagnosticLogger(IConfiguration configuration, IHttpContextAccessor contextAccessor)
: base(configuration)
{
this.contextAccessor = contextAccessor;
}
public void Log(string message, Dictionary<string, object> additionalInfo)
{
if (!Convert.ToBoolean(configuration[$"{configModuleStatus}:Diagnostic"]))
{
return;
}
var logDetail = new DiagnosticLogDetail();
logDetail.PopulateModel(message, contextAccessor.HttpContext, configuration, additionalInfo, false);
logger.Information("{Timestamp}{Message}{Location}{Product}" +
"{Hostname}" +
"{UserId}{UserName}{SessionId}{CorrelationId}{AdditionalInfo}",
logDetail.Timestamp, logDetail.Message,
logDetail.Location,
logDetail.Product,
logDetail.Hostname, logDetail.UserId,
logDetail.UserName, logDetail.SessionId,
logDetail.CorrelationId,
logDetail.AdditionalInfoDictionary.JsonSerialize());
}
}
}