Skip to content

Commit 799f955

Browse files
committed
Update the CHANGELOG and README for version 1.3.0
1 parent cd80817 commit 799f955

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

CHANGELOG.md

+53-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,53 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.3.0][1.3.0] - 2025-04-19
8+
9+
- 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.
10+
11+
Before (1.2.0)
12+
13+
```xml
14+
<event logger="Microsoft.EntityFrameworkCore.Database.Command" timestamp="2003-01-04T15:09:26.535+01:00" level="INFO">
15+
<properties>
16+
<data name="elapsed" value="10" />
17+
<!-- ... -->
18+
<data name="EventId.Id" value="20101" />
19+
<data name="EventId.Name" value="Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted" />
20+
</properties>
21+
<message>Executed DbCommand ("10"ms) [Parameters=[""], CommandType='Text', CommandTimeout='30']"
22+
""SELECT COUNT(*) FROM \"sqlite_master\" WHERE \"type\" = 'table' AND \"rootpage\" IS NOT NULL;"</message>
23+
</event>
24+
```
25+
26+
After (1.3.0)
27+
28+
```xml
29+
<event logger="Microsoft.EntityFrameworkCore.Database.Command" timestamp="2003-01-04T15:09:26.535+01:00" level="INFO">
30+
<properties>
31+
<data name="elapsed" value="10" />
32+
<!-- ... -->
33+
<data name="EventId.Id" value="20101" />
34+
<data name="EventId.Name" value="Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted" />
35+
</properties>
36+
<message>Executed DbCommand (10ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
37+
SELECT COUNT(*) FROM "sqlite_master" WHERE "type" = 'table' AND "rootpage" IS NOT NULL;</message>
38+
</event>
39+
```
40+
41+
- 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.
42+
43+
```csharp
44+
var formatter = new Log4NetTextFormatter(options => options.UseMessageFormatter((logEvent, formatProvider) =>
45+
{
46+
if (logEvent.Properties.TryGetValue("UppercaseMessage", out var up) && up is ScalarValue { Value: true })
47+
{
48+
return logEvent.RenderMessage(formatProvider).ToUpperInvariant();
49+
}
50+
return logEvent.RenderMessage(formatProvider);
51+
}));
52+
```
53+
754
## [1.2.0][1.2.0] - 2024-09-10
855

956
- Add support for .NET 8 and mark `Serilog.Formatting.Log4Net` as [trimmable](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/).
@@ -40,20 +87,20 @@ Serilog.Formatting.Log4Net.Log4NetTextFormatter::Log4JFormatter, Serilog.Formatt
4087
- Converted the `LineEndingExtensions` class from public to internal
4188
- 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
4289

43-
Before (1.0.0-rc.2):
90+
Before (1.0.0-rc.2)
4491

4592
```xml
4693
<log4j:event timestamp="1041689366535" level="INFO" xmlns:log4j="http://jakarta.apache.org/log4j/">
4794
<log4j:message><![CDATA[Hello from Serilog]]></log4j:message>
48-
</log4j:event>
95+
</log4j:event>
4996
```
5097

5198
After (1.0.0-rc.3)
5299

53100
```xml
54101
<log4j:event timestamp="1041689366535" level="INFO">
55102
<log4j:message><![CDATA[Hello from Serilog]]></log4j:message>
56-
</log4j:event>
103+
</log4j:event>
57104
```
58105

59106
## [1.0.0-rc.2][1.0.0-rc.2] - 2021-03-25
@@ -62,7 +109,7 @@ After (1.0.0-rc.3)
62109
- The `Log4NetTextFormatterOptionsBuilder` constructor is now internal
63110
- Include the index in the property name when formatting a SequenceValue
64111

65-
Before (1.0.0-rc.1):
112+
Before (1.0.0-rc.1)
66113

67114
```xml
68115
<log4net:data name="Args" value="--first-argument" />
@@ -88,7 +135,8 @@ Still trying to figure out how to make everything fit together with [MinVer](htt
88135

89136
- Implement log4j compatibility mode.
90137

91-
[Unreleased]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.1.0...HEAD
138+
[Unreleased]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.3.0...HEAD
139+
[1.3.0]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.2.0...1.3.0
92140
[1.2.0]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.1.0...1.2.0
93141
[1.1.0]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.0.2...1.1.0
94142
[1.0.2]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.0.1...1.0.2

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,36 @@ Running this app writes the following XML events into the `logs.xml` file in the
6060

6161
You can configure `Log4NetTextFormatter` in multiple ways, the fluent options builder will help you discover all the possibilities.
6262

63+
### Message formatting
64+
65+
Since version 1.3.0, the contents of the `message` XML elements can be customized by using the new `UseMessageFormatter` method. For example, to always [format the message](https://github.com/serilog/serilog/wiki/Formatting-Output) by switching off quoting of strings, use this:
66+
67+
```csharp
68+
new Log4NetTextFormatter(options => options.UseMessageFormatter(FormatMessageWithoutQuotes));
69+
70+
static string FormatMessageWithoutQuotes(LogEvent logEvent, IFormatProvider? formatProvider)
71+
{
72+
var messageFormatter = new MessageTemplateTextFormatter("{Message:l}", formatProvider);
73+
using var output = new StringWriter();
74+
messageFormatter.Format(logEvent, output);
75+
return output.ToString();
76+
}
77+
```
78+
79+
> [!NOTE]
80+
> By default, only log events coming from `Microsoft.Extensions.Logging` are formatted without quotes.
81+
82+
To restore the behaviour of version 1.2.0 and earlier (i.e. quoting of all strings), apply te following message formatter:
83+
84+
```csharp
85+
new Log4NetTextFormatter(options => options.UseMessageFormatter((logEvent, formatProvider) =>
86+
{
87+
return logEvent.RenderMessage(formatProvider);
88+
}));
89+
```
90+
91+
See also the [release notes](CHANGELOG.md) of version 1.3.0 for a concrete example of what changed from previous versions.
92+
6393
### Exception formatting
6494

6595
By default, Log4NetTextFormatter formats exception by calling [ToString()](https://docs.microsoft.com/en-us/dotnet/api/system.exception.tostring). You can customise this behaviour by setting your own formatting delegate. For example, you could use [Ben.Demystifier](https://github.com/benaadams/Ben.Demystifier/) like this:

0 commit comments

Comments
 (0)