You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use [Log4View](https://www.log4view.com) to look at log files produced with this formatter.
6
+
5
7
## Getting started
6
8
7
9
**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.
@@ -67,6 +69,28 @@ You can remove the `log4net` XML namespace by setting the `Log4NetXmlNamespace`
By default, Log4NetTextFormatter indents XML elements with two spaces. You can configure it to use either spaces or tabs. For example, indent XML elements with one tab:
Or you can use no indentation at all, having log4net events written on a single line:
89
+
90
+
```c#
91
+
newLog4NetTextFormatter(c=>c.UseNoIndentation())
92
+
```
93
+
70
94
#### Format provider
71
95
72
96
By default, Log4NetTextFormatter uses the invariant culture (Serilog's default) when formatting Serilog properties that implement the `IFormattable` interface. It can be configured to use culture-specific formatting information. For example, to use the Swiss French culture:
@@ -88,15 +112,15 @@ new Log4NetTextFormatter(c => c.UsePropertyFilter((_, name) => name != "MySecret
88
112
You can also combine options, for example, both removing namespaces and using Ben.Demystifier for exception formatting:
The log4Net XML format defines some special attributes which are not included by default in Serilog events. They can be added by using the appropriate Serilog enrichers.
123
+
The log4Net XML format defines some special attributes which are not included by default in Serilog events. They can be added by using the appropriate Serilog [enrichers](https://github.com/serilog/serilog/wiki/Enrichment).
100
124
101
125
#### Thread Id
102
126
@@ -121,3 +145,20 @@ Include the machine name in log4net events by using [Serilog.Enrichers.Environme
Combining these three enrichers wil produce a log event like this, including `thread`, `domain` and `username` attributes plus a `log4net:HostName` property containing the machine name:
The [Serilog.Sinks.Log4Net](https://github.com/serilog/serilog-sinks-log4net) project is similar but depends on the log4net NuGet package whereas Serilog.Formatting.Log4Net does not. Also, Serilog.Sinks.Log4Net is a sink so you have to configure log4net in addition to configuring Serilog.
163
+
164
+
The [Serilog.Sinks.Udp](https://github.com/FantasticFiasco/serilog-sinks-udp) project also provides a [Log4Net formatter](https://github.com/FantasticFiasco/serilog-sinks-udp/blob/v7.1.0/src/Serilog.Sinks.Udp/Sinks/Udp/TextFormatters/Log4netTextFormatter.cs) but it writes XML *manually* (without using an [XmlWriter](https://docs.microsoft.com/en-us/dotnet/api/System.Xml.XmlWriter)), completely ignores Serilog properties, is not configurable at all (indentation, newlines, namespaces etc.) and is not documented.
0 commit comments