Elastic.CommonSchema.Log4net 8.12.1

Prefix Reserved
dotnet add package Elastic.CommonSchema.Log4net --version 8.12.1                
NuGet\Install-Package Elastic.CommonSchema.Log4net -Version 8.12.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Elastic.CommonSchema.Log4net" Version="8.12.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Elastic.CommonSchema.Log4net --version 8.12.1                
#r "nuget: Elastic.CommonSchema.Log4net, 8.12.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Elastic.CommonSchema.Log4net as a Cake Addin
#addin nuget:?package=Elastic.CommonSchema.Log4net&version=8.12.1

// Install Elastic.CommonSchema.Log4net as a Cake Tool
#tool nuget:?package=Elastic.CommonSchema.Log4net&version=8.12.1                

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:

  • labels is taken from metadata (string and boolean properties)
  • log.origin.file.name is taken from LocationInformation
  • log.origin.file.line is taken from LocationInformation
  • log.origin.function is taken from LocationInformation
  • event.created is taken from timestamp
  • event.timezone is equal to local timezone
  • host.hostname is taken from HostName property
  • process.thread.id is taken from ThreadName if it has numeric value
  • process.thread.name is taken from ThreadName if it doesn't have numeric value
  • service.name is taken from entry or calling assembly
  • service.version is taken from entry or calling assembly
  • error.message is taken from ExceptionObject
  • error.type is taken from ExceptionObject
  • error.stacktrace is taken from ExceptionObject
  • 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!",
    "ecs.version": "8.6.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
    }
}

This software is Copyright (c) 2014-2020 by Elasticsearch BV.

This is free software, licensed under: The Apache License Version 2.0.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1 77 10/3/2024
8.12.0 99 9/26/2024
8.11.1 3,927 6/10/2024
8.11.0 1,308 4/10/2024
8.6.1 20,833 8/3/2023
8.6.0 2,557 5/9/2023
8.4.0-alpha4 159 3/28/2023
8.4.0-alpha3 152 3/15/2023
8.4.0-alpha2 160 3/1/2023
8.4.0-alpha1 172 2/20/2023