Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 1566098

Browse files
committed
Splunk OTel .NET 1.9.0 - log4net documentation
1 parent 188db21 commit 1566098

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

gdi/get-data-in/application/otel-dotnet/instrumentation/connect-traces-logs.rst

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ Connect .NET trace data with logs using OpenTelemetry instrumentation
77
.. meta::
88
:description: Automatic correlation between logs and traces provided by the Splunk Distribution of OpenTelemetry .NET.
99

10-
The Splunk Distribution of OpenTelemetry .NET automatically exports logs enriched with tracing context from any application that uses logging API from :new-page:`Microsoft.Extensions.Logging <https://www.nuget.org/packages/Microsoft.Extensions.Logging>` for logging.
10+
The Splunk Distribution of OpenTelemetry .NET automatically exports logs enriched with tracing context from any application that uses logging API from:
11+
12+
* :new-page:`Microsoft.Extensions.Logging <https://www.nuget.org/packages/Microsoft.Extensions.Logging>`,
13+
* :new-page:`log4net <https://www.nuget.org/packages/log4net>`.
14+
1115

1216
Application logs are enriched with tracing metadata and then exported to a local instance of the OpenTelemetry Collector in ``OTLP`` format.
1317

@@ -48,9 +52,10 @@ The following is an example of logs produced by a sample console application:
4852
Check compatibility and requirements
4953
====================================================
5054

51-
.. note:: Automatic log to trace correlation only works for .NET applications. For .NET Framework use manual correlation. See :ref:`manual-trace-logs-correlation-otel`.
55+
.. note:: Automatic log to trace correlation for ``Microsoft.Extensions.Logging`` only works for .NET applications. For .NET Framework use manual correlation. See :ref:`manual-trace-logs-correlation-otel`.
5256

53-
``Microsoft.Extensions.Logging`` version ``9.0.0`` and higher are supported.
57+
* ``Microsoft.Extensions.Logging`` version ``9.0.0`` and higher are supported,
58+
* ``log4net`` version from ``2.0.13`` to ``4.0.0`` are supported. Environmental variable ``OTEL_DOTNET_AUTO_LOGS_ENABLE_LOG4NET_BRIDGE`` needs to be set to ``true``.
5459

5560
.. _dotnet-otel-enable-log-correlation:
5661

@@ -94,8 +99,27 @@ Manual log to trace correlation
9499

95100
You can configure logging libraries to include tracing attributes in logs written to existing logs destination.
96101

102+
``log4net``
103+
-----------------------------------------------
104+
105+
You can modify ``conversionPattern`` in your log4net appender to include tracing attributes in logs written to existing logs destination. Following properties are set by default on the collection of logging event's properties:
106+
107+
* `trace_id`
108+
* `span_id`
109+
* `trace_flags`.
110+
111+
Example how to configure ``ConsoleAppender``
112+
113+
.. code-block:: text
114+
115+
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
116+
<layout type="log4net.Layout.PatternLayout">
117+
<conversionPattern value="%date [%thread] %-5level %logger - %message span_id=%property{span_id} trace_id=%property{trace_id} trace_flags=%property{trace_flags} test_key=%property{test_key}%newline" />
118+
</layout>
119+
</appender>
120+
97121
``NLog``
98-
----------------------------------------------------
122+
-----------------------------------------------
99123

100124
You can use :new-page:`NLog.DiagnosticSource <https://www.nuget.org/packages/NLog.DiagnosticSource>`. See the :new-page:`NLog official documentation <https://github.com/NLog/NLog.DiagnosticSource>` for more information.
101125

0 commit comments

Comments
 (0)