Skip to content

Version 1.3.0

Compare
Choose a tag to compare
@github-actions github-actions released this 19 Apr 16:19
· 12 commits to main since this release
  • The formatting of the message XML element has changed. If a log event is coming from Microsoft.Extensions.Logging, then the message is now formatted by switching off quoting of strings. The formatting of properties remains unchanged.

Before (1.2.0)

<event logger="Microsoft.EntityFrameworkCore.Database.Command" timestamp="2003-01-04T15:09:26.535+01:00" level="INFO">
  <properties>
    <data name="elapsed" value="10" />
    <!-- ... -->
    <data name="EventId.Id" value="20101" />
    <data name="EventId.Name" value="Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted" />
  </properties>
  <message>Executed DbCommand ("10"ms) [Parameters=[""], CommandType='Text', CommandTimeout='30']"
""SELECT COUNT(*) FROM \"sqlite_master\" WHERE \"type\" = 'table' AND \"rootpage\" IS NOT NULL;"</message>
</event>

After (1.3.0)

<event logger="Microsoft.EntityFrameworkCore.Database.Command" timestamp="2003-01-04T15:09:26.535+01:00" level="INFO">
  <properties>
    <data name="elapsed" value="10" />
    <!-- ... -->
    <data name="EventId.Id" value="20101" />
    <data name="EventId.Name" value="Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted" />
  </properties>
  <message>Executed DbCommand (10ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*) FROM "sqlite_master" WHERE "type" = 'table' AND "rootpage" IS NOT NULL;</message>
</event>
  • The message formatting behaviour can be configured with the new UseMessageFormatter() method of the options' builder. For example, all log events with the UppercaseMessage property set to true can have their messages uppercased.
var formatter = new Log4NetTextFormatter(options => options.UseMessageFormatter((logEvent, formatProvider) =>
{
    if (logEvent.Properties.TryGetValue("UppercaseMessage", out var up) && up is ScalarValue { Value: true })
    {
        return logEvent.RenderMessage(formatProvider).ToUpperInvariant();
    }
    return logEvent.RenderMessage(formatProvider);
}));