Elastic.CommonSchema.Log4net
9.0.0
Prefix Reserved
dotnet add package Elastic.CommonSchema.Log4net --version 9.0.0
NuGet\Install-Package Elastic.CommonSchema.Log4net -Version 9.0.0
<PackageReference Include="Elastic.CommonSchema.Log4net" Version="9.0.0" />
<PackageVersion Include="Elastic.CommonSchema.Log4net" Version="9.0.0" />
<PackageReference Include="Elastic.CommonSchema.Log4net" />
paket add Elastic.CommonSchema.Log4net --version 9.0.0
#r "nuget: Elastic.CommonSchema.Log4net, 9.0.0"
#:package Elastic.CommonSchema.Log4net@9.0.0
#addin nuget:?package=Elastic.CommonSchema.Log4net&version=9.0.0
#tool nuget:?package=Elastic.CommonSchema.Log4net&version=9.0.0
Elastic Common Schema log4net Layout
This Layout implementation formats a log4net event into a JSON representation that adheres to the Elastic Common Schema specification.
Packages
The .NET assemblies are published to NuGet under the package name Elastic.CommonSchema.Log4net
How to use from configuration
Specify layout type in appender's configuration:
<log4net>
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="Elastic.CommonSchema.Log4net.EcsLayout, Elastic.CommonSchema.Log4net" />
</appender>
</log4net>
How to use from API
var hierarchy = (Hierarchy)LogManager.CreateRepository(Guid.NewGuid().ToString());
var appender = new ConsoleAppender { Layout = new EcsLayout() }; // Use the ECS layout.
hierarchy.Root.AddAppender(appender);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
The Layout = new EcsLayout() line then instructs log4net to use ECS layout.
The sample above uses the console appender, but you are free to use any appender of your choice, perhaps consider using a
filesystem target and Elastic Filebeat for durable and reliable ingestion.
ECS Aware Properties
Any valid ECS log template properties that is available under LogTemplateProperties.* e.g LogTemplateProperties.TraceId
is supported and will directly set the appropriate ECS field.
Output
Apart from mandatory fields, the output contains additional data:
labelsis taken frommetadata(string and boolean properties)log.origin.file.nameis taken fromLocationInformationlog.origin.file.lineis taken fromLocationInformationlog.origin.functionis taken fromLocationInformationevent.createdis taken from timestampevent.timezoneis equal to local timezonehost.hostnameis taken fromHostNamepropertyprocess.thread.idis taken fromThreadNameif it has numeric valueprocess.thread.nameis taken fromThreadNameif it doesn't have numeric valueservice.nameis taken from entry or calling assemblyservice.versionis taken from entry or calling assemblyerror.messageis taken fromExceptionObjecterror.typeis taken fromExceptionObjecterror.stacktraceis taken fromExceptionObjectmetadatais taken from properties. It also contains message template and arguments in case a formatted message was logged
Sample log event output (formatted for readability):
{
"@timestamp": "2022-08-28T14:06:28.5121651+02:00",
"log.level": "INFO",
"message": "Hi! Welcome to example!",
"ecs.version": "9.0.0",
"log": {
"logger": "Elastic.CommonSchema.Log4net.Example.Program",
"original": null,
"origin": {
"file": {
"name": "C:\\Development\\Elastic.CommonSchema.Log4net.Example\\Program.cs",
"line": 17
},
"function": "Main"
}
},
"labels": {
"MessageTemplate": "{0}! Welcome to example!"
"0": "Hi"
},
"agent": {
"type": "Elastic.CommonSchema.Log4net.Example",
"version": "1.0.0.0"
},
"event": {
"created": "2024-04-02T17:43:55.3829964+02:00",
"timezone": "W. Europe Standard Time"
},
"host": {
"os": {
"full": "Microsoft Windows 10.0.22631",
"platform": "Win32NT",
"version": "10.0.22631.0"
},
"architecture": "X64",
"hostname": "HGU780D3",
"name": "HGU780D3"
},
"process": {
"name": "Elastic.CommonSchema.Log4net.Example",
"pid": 39652,
"thread.id": 17,
"thread.name": ".NET Long Running Task",
"title": ""
},
"service": {
"name": "Elastic.CommonSchema.Log4net.Example",
"type": "dotnet",
"version": "1.0.0.0"
},
"user": {
"domain": "company",
"name": "user"
},
"metadata": {
"GlobalAmountProperty": 3.14
}
}
Copyright and License
This software is Copyright (c) 2014-2020 by Elasticsearch BV.
This is free software, licensed under: The Apache License Version 2.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Elastic.CommonSchema (>= 9.0.0)
- log4net (>= 2.0.17)
-
.NETStandard 2.0
- Elastic.CommonSchema (>= 9.0.0)
- log4net (>= 2.0.17)
-
.NETStandard 2.1
- Elastic.CommonSchema (>= 9.0.0)
- log4net (>= 2.0.17)
-
net8.0
- Elastic.CommonSchema (>= 9.0.0)
- log4net (>= 2.0.17)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 9.0.0 | 1,805 | 8/13/2025 |
| 8.19.0 | 199 | 8/13/2025 |
| 8.18.2 | 1,003 | 6/27/2025 |
| 8.18.1 | 912 | 5/28/2025 |
| 8.18.0 | 399 | 5/22/2025 |
| 8.12.3 | 35,991 | 11/26/2024 |
| 8.12.2 | 7,211 | 10/22/2024 |
| 8.12.1 | 4,975 | 10/3/2024 |
| 8.12.0 | 202 | 9/26/2024 |
| 8.11.1 | 30,744 | 6/10/2024 |
| 8.11.0 | 7,725 | 4/10/2024 |
| 8.6.1 | 36,114 | 8/3/2023 |
| 8.6.0 | 3,595 | 5/9/2023 |
| 8.4.0-alpha4 | 302 | 3/28/2023 |
| 8.4.0-alpha3 | 271 | 3/15/2023 |
| 8.4.0-alpha2 | 260 | 3/1/2023 |
| 8.4.0-alpha1 | 281 | 2/20/2023 |