Elastic.CommonSchema.Log4net
8.4.0-alpha4
Prefix Reserved
See the version list below for details.
dotnet add package Elastic.CommonSchema.Log4net --version 8.4.0-alpha4
NuGet\Install-Package Elastic.CommonSchema.Log4net -Version 8.4.0-alpha4
<PackageReference Include="Elastic.CommonSchema.Log4net" Version="8.4.0-alpha4" />
paket add Elastic.CommonSchema.Log4net --version 8.4.0-alpha4
#r "nuget: Elastic.CommonSchema.Log4net, 8.4.0-alpha4"
// Install Elastic.CommonSchema.Log4net as a Cake Addin #addin nuget:?package=Elastic.CommonSchema.Log4net&version=8.4.0-alpha4&prerelease // Install Elastic.CommonSchema.Log4net as a Cake Tool #tool nuget:?package=Elastic.CommonSchema.Log4net&version=8.4.0-alpha4&prerelease
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:
log.origin.file.name
is taken fromLocationInformation
log.origin.file.line
is taken fromLocationInformation
log.origin.function
is taken fromLocationInformation
event.created
is taken from timestampevent.timezone
is equal to local timezonehost.hostname
is taken fromHostName
propertyprocess.thread.id
is taken fromThreadName
if it has numeric valueprocess.thread.name
is taken fromThreadName
if it doesn't have numeric valueservice.name
is taken from entry or calling assemblyservice.version
is taken from entry or calling assemblyerror.message
is taken fromExceptionObject
error.type
is taken fromExceptionObject
error.stacktrace
is taken fromExceptionObject
metadata
is 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!",
"metadata": {
"global_property": "Example",
"message_template": "{0}! Welcome to example!"
"0": "Hi"
},
"ecs": {
"version": "8.3.1"
},
"event": {
"timezone": "Central European Time",
"created": "2022-08-28T14:06:28.5121651+02:00"
},
"host": {
"hostname": "HGU780D3"
},
"log": {
"logger": "Elastic.CommonSchema.Log4net.Example.Program",
"original": null,
"origin": {
"file": {
"name": "C:\\Development\\Elastic.CommonSchema.Log4net.Example\\Program.cs",
"line": 17
},
"function": "Main"
}
},
"process": {
"thread": {
"id": 1
}
},
"service": {
"name": "Elastic.CommonSchema.Log4net.Example",
"version": "1.0.0.0"
}
}
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 was computed. 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. |
.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 is compatible. net462 was computed. 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.1
- Elastic.CommonSchema (>= 8.4.0-alpha4)
- log4net (>= 2.0.15)
-
.NETStandard 2.0
- Elastic.CommonSchema (>= 8.4.0-alpha4)
- log4net (>= 2.0.15)
-
.NETStandard 2.1
- Elastic.CommonSchema (>= 8.4.0-alpha4)
- log4net (>= 2.0.15)
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 |
---|---|---|
8.12.3 | 748 | 11/26/2024 |
8.12.2 | 2,305 | 10/22/2024 |
8.12.1 | 1,045 | 10/3/2024 |
8.12.0 | 119 | 9/26/2024 |
8.11.1 | 7,337 | 6/10/2024 |
8.11.0 | 2,589 | 4/10/2024 |
8.6.1 | 25,634 | 8/3/2023 |
8.6.0 | 2,628 | 5/9/2023 |
8.4.0-alpha4 | 165 | 3/28/2023 |
8.4.0-alpha3 | 158 | 3/15/2023 |
8.4.0-alpha2 | 168 | 3/1/2023 |
8.4.0-alpha1 | 180 | 2/20/2023 |