Tags: serilog-contrib/serilog-formatting-log4net
Tags
- Properties whose values are `null` are now always serialized with a… … `value` attribute. Thanks to @southernprogrammer for reporting this issue. See the [Null text](https://github.com/serilog-contrib/serilog-formatting-log4net#null-text) documentation in the README for more information. Before (1.3.1) ```xml <log4net:properties> <log4net:data name="key" /> </log4net:properties> ``` After (1.4.0) ```xml <log4net:properties> <log4net:data name="key" value="(null)" /> </log4net:properties> ```
- Log events coming from `Microsoft.Extensions.Logging` are now ident… …ified if they have **either** an `EventId.Id` or an `EventId.Name` property. Previously, log events coming from `Microsoft.Extensions.Logging` were identified if they had **both** an `Id` and a `Name` property.
- The formatting of the `message` XML element has changed. If a log e… …vent 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) ```xml <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) ```xml <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. ```csharp 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); })); ```
- Add support for .NET 8 and mark `Serilog.Formatting.Log4Net` as [tr… …immable](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained) for [AOT compatibility](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/).
- Add a new `Log4NetTextFormatter.Log4JFormatter` static property whi… …ch is configured for the log4j XML layout. This static property is also useful when using the [Serilog.Settings.Configuration](https://github.com/serilog/serilog-settings-configuration/) package where it can be used with the following accessor: ```text Serilog.Formatting.Log4Net.Log4NetTextFormatter::Log4JFormatter, Serilog.Formatting.Log4Net ```
- Add support for .NET 6. It will be beneficial for [string interpola… …tion](https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-6/#arrays-strings-spans) which is used extensively through the project. See [Are there benefits in producing a .NET 6.0 version of a .NET Standard 2.0 library?](https://stackoverflow.com/questions/70778797/are-there-benefits-in-producing-a-net-6-0-version-of-a-net-standard-2-0-librar/72266562#72266562) on Stack Overflow.
- Add README and release notes (link to https://github.com/serilog-co… …ntrib/serilog-formatting-log4net/blob/main/CHANGELOG.md) in the NuGet package
- Replace `UseLog4NetXmlNamespace(null)` with `UseNoXmlNamespace()` - Reduce the public API surface - Removed all property getters on `Log4NetTextFormatterOptionsBuilder` - Converted the `LineEndingExtensions` class from public to internal - Improve log4j compatibility mode: don't write the `xmlns:log4j` attribute to be [exactly compatible](https://github.com/apache/log4j/blob/v1_2_17/src/main/java/org/apache/log4j/xml/XMLLayout.java#L137-L145) with log4j Before (1.0.0-rc.2): ```xml <log4j:event timestamp="1041689366535" level="INFO" xmlns:log4j="http://jakarta.apache.org/log4j/"> <log4j:message><![CDATA[Hello from Serilog]]></log4j:message> </log4j:event> ``` After (1.0.0-rc.3) ```xml <log4j:event timestamp="1041689366535" level="INFO"> <log4j:message><![CDATA[Hello from Serilog]]></log4j:message> </log4j:event> ```
PreviousNext