Hi @catmanjan , Welcome to Microsoft Q&A,
You can remove the info: prefix from the console log output via a custom log formatter. The commonly used simple formatter does not allow you to directly remove the log level prefix.
using System;
using System.IO;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
public class CustomConsoleFormatter : ConsoleFormatter
{
public CustomConsoleFormatter() : base("custom")
{
}
public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeProvider scopeProvider, TextWriter textWriter)
{
var timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
textWriter.WriteLine($"{timestamp} {logEntry.State}");
}
}
Add the formatter in Program.cs
builder.Logging.AddConsoleFormatter<CustomConsoleFormatter, ConsoleFormatterOptions>();
Edit appsettings.json
{
"Logging": {
"Console": {
"FormatterName": "custom"
}
}
}
You can also check out the official documentation examples: Logging in C# and .NET
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.