Using Serilog, I want to have a new property Identifier (right after "Timestamp") in the log file like below:
{"Timestamp":"2019-10-11T12:18:51.1488404+08:00", "Identifier":"", "Level":"Information","MessageTemplate":"Log {CurrentThreadId}","Properties":{"CurrentThreadId":4,"MainThreadId":1}}
I have added LogContext.PushProperty like below.
builder.Services.AddProblemDetails(options =>
options.CustomizeProblemDetails = (context) =>
{
var mathErrorFeature = context.HttpContext.Features
.Get<MathErrorFeature>();
if (mathErrorFeature is not null)
{
(string Detail, string Type) details = mathErrorFeature.MathError switch
{
MathErrorType.DivisionByZeroError =>
("Divison by zero is not defined.",
"https://wikipedia.org/wiki/Division_by_zero"),
_ => ("Negative or complex numbers are not valid input.",
"https://wikipedia.org/wiki/Square_root")
};
context.ProblemDetails.Type = details.Type;
context.ProblemDetails.Title = "Bad Input";
context.ProblemDetails.Detail = details.Detail;
var identifier = $"Iden:{Guid.New()}";
LogContext.PushProperty("Identifier", identifier);
}
}
);
Will this work the way I want the Identifier to be appended to the log file? If not, how to do that in Serilog?