Closed eusebiu closed 3 years ago
This has been possible since the very beginning. The IFileLogEntryTextBuilder
interface provides full control over log message formatting. However, you're better off subclassing the default implementation of this interface (FileLogEntryTextBuilder
). E.g.:
class CleanFileLogEntryTextBuilder : FileLogEntryTextBuilder
{
protected override int MessagePaddingWidth => 0;
public override void BuildEntryText(StringBuilder sb, string categoryName, LogLevel logLevel, EventId eventId, string message, Exception exception, IExternalScopeProvider scopeProvider, DateTimeOffset timestamp)
{
if (!string.IsNullOrEmpty(message))
AppendMessage(sb, message);
if (exception != null)
AppendException(sb, exception);
}
}
Of course, you need to tell the library to use your custom formatter. One way to do this:
builder.AddFile(o =>
{
o.TextBuilder = new CleanFileLogEntryTextBuilder();
// ...rest of configuration is ommitted for brevity...
});
Thanks! Works fine!
Would be nice to have the possibility to clean the output of the category name:
https://stackoverflow.com/questions/55924730/is-it-possible-to-disable-category-output-in-net-core-consolelogger-and-debuglo
Thanks!