Skip to content

Commit 7d9bee9

Browse files
committed
Improve the "Getting started" section of the README
By giving an example that demonstrates how Serilog properties are handled by Log4NetTextFormatter.
1 parent 0dce471 commit 7d9bee9

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dotnet add package Serilog.Formatting.Log4Net
1414

1515
**Serilog.Formatting.Log4Net** provides the `Log4NetTextFormatter` class which implements Serilog's [ITextFormatter](https://github.com/serilog/serilog/blob/v2.0.0/src/Serilog/Formatting/ITextFormatter.cs#L20-L31) interface.
1616

17-
Here's how to use it with a file sink in a simple *Hello World* app:
17+
Here's how to use it with a [file sink](https://www.nuget.org/packages/Serilog.Sinks.File/) in a simple *Hello World* app:
1818

1919
```c#
2020
using System;
@@ -23,13 +23,14 @@ using Serilog.Formatting.Log4Net;
2323

2424
static class Program
2525
{
26-
static void Main()
26+
static void Main(string[] args)
2727
{
2828
var logger = new LoggerConfiguration()
29-
.WriteTo.File(new Log4NetTextFormatter(), "logs.xml")
29+
.Enrich.WithProperty("AppName", "Program")
30+
.WriteTo.File(new Log4NetTextFormatter(c => c.UseCDataMode(CDataMode.Never)), "logs.xml")
3031
.CreateLogger();
3132

32-
logger.Information("Start app");
33+
logger.Information("Start app with {Args}", args);
3334
Console.WriteLine("Hello World!");
3435
logger.Information("Stop app");
3536
}
@@ -39,11 +40,19 @@ static class Program
3940
Running this app writes the following XML events into the `logs.xml` file in the current working directory:
4041

4142
```xml
42-
<log4net:event timestamp="2020-06-28T10:03:31.685165+02:00" level="INFO" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2/">
43-
<log4net:message><![CDATA[Start app]]></log4net:message>
43+
<log4net:event timestamp="2021-02-24T18:23:40.4496605+01:00" level="INFO" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2/">
44+
<log4net:properties>
45+
<log4net:data name="Args[0]" value="--first-argument" />
46+
<log4net:data name="Args[1]" value="--second-argument" />
47+
<log4net:data name="AppName" value="Program" />
48+
</log4net:properties>
49+
<log4net:message>Start app with ["--first-argument", "--second-argument"]</log4net:message>
4450
</log4net:event>
45-
<log4net:event timestamp="2020-06-28T10:03:31.705216+02:00" level="INFO" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2/">
46-
<log4net:message><![CDATA[Stop app]]></log4net:message>
51+
<log4net:event timestamp="2021-02-24T18:23:40.5086666+01:00" level="INFO" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2/">
52+
<log4net:properties>
53+
<log4net:data name="AppName" value="Program" />
54+
</log4net:properties>
55+
<log4net:message>Stop app</log4net:message>
4756
</log4net:event>
4857
```
4958

0 commit comments

Comments
 (0)