ZLogger
ZLogger copied to clipboard
How to use customize structured logging
Hello I would like to customize structedLogging Is it possible??
Or can I make custom log processor?? your example doesn't work MessageTest.cs It output nothing...
And I would like to use Payload in custom log processor.
this code is using Prefix, Suffix
builder.AddZLoggerConsole(options =>
{
options.PrefixFormatter = (writer, info) =>
{
var strList = new List<string>()
{
$"\"CategoryName\":\"{info.CategoryName}\"",
$"\"LogLevel\":\"{info.LogLevel}\"",
$"\"Timestamp\":\"{info.Timestamp.DateTime.ToLocalTime()}\"",
$"\"Exception\":\"{info.Exception}\"",
};
var outStr = String.Join(", ", strList);
ZString.Utf8Format(writer, "{0}, \"Message\":\"", "{" + outStr);
};
}
this code is using structedLogging I would like to erase EventID or some values I don't use.
builder.AddZLoggerConsole(options =>
{
options.PrefixFormatter = (writer, info) =>
{
options.EnableStructuredLogging = true;
options.StructuredLoggingFormatter = (writer, info) =>
{
//writer.WriteString(applicationKey, applicationValue);
info.WriteToJsonWriter(writer);
};
options.JsonSerializerOptions = new JsonSerializerOptions
{
WriteIndented = false,
IgnoreNullValues = true,
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
};
};
}