Elastic.CommonSchema.NLog
8.11.0
Prefix Reserved
See the version list below for details.
dotnet add package Elastic.CommonSchema.NLog --version 8.11.0
NuGet\Install-Package Elastic.CommonSchema.NLog -Version 8.11.0
<PackageReference Include="Elastic.CommonSchema.NLog" Version="8.11.0" />
paket add Elastic.CommonSchema.NLog --version 8.11.0
#r "nuget: Elastic.CommonSchema.NLog, 8.11.0"
// Install Elastic.CommonSchema.NLog as a Cake Addin #addin nuget:?package=Elastic.CommonSchema.NLog&version=8.11.0 // Install Elastic.CommonSchema.NLog as a Cake Tool #tool nuget:?package=Elastic.CommonSchema.NLog&version=8.11.0
Elastic Common Schema NLog Layout
This Layout implementation formats an NLog 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.NLog
How to use from API
Layout.Register<EcsLayout>("EcsLayout"); // Register the ECS layout.
var config = new LoggingConfiguration();
var consoleTarget = new ConsoleTarget("console") { Layout = new EcsLayout() }; // Use the ECS layout.
config.AddRule(LogLevel.Debug, LogLevel.Fatal, consoleTarget);
LogManager.Configuration = config;
var logger = LogManager.GetCurrentClassLogger();
In the code snippet above Layout.Register<EcsLayout>("EcsLayout")
registers the EcsLayout
with NLog.
The Layout = new EcsLayout()
line then instructs NLog to use the registered layout.
The sample above uses the console target, but you are free to use any target of your choice, perhaps consider using a
filesystem target and Elastic Filebeat for durable and reliable ingestion.
How to use from NLog.config
<nlog>
<extensions>
<add assembly="Elastic.Apm.NLog"/>
<add assembly="Elastic.CommonSchema.NLog"/>
</extensions>
<targets>
<target name="console" type="console">
<layout xsi:type="EcsLayout">
<metadata name="MyProperty" layout="MyPropertyValue" />
<label name="MyLabel" layout="MyLabelValue" />
<tag layout="MyTagValue" />
</layout>
</target>
</targets>
<rules>
<logger name="*" minLevel="Debug" writeTo="Console" />
</rules>
</nlog>
EcsLayout Parameter Options
Metadata Options
- IncludeEventProperties - Include LogEvent properties as metadata. Default:
true
- IncludeScopeProperties - Include NLog Scope Context Properties as metadata. Default:
false
- ExcludeProperties - Comma separated string with names which properties to exclude.
- IncludeEventProperties - Include LogEvent properties as metadata. Default:
Event Options
- EventAction -
- EventCategory -
- EventId -
- EventKind -
- EventSeverity -
Agent Options
- AgentId -
- AgentName -
- AgentType -
- AgentVersion -
Process Options
- ProcessExecutable - Default:
${processname:FullName=true}
- ProcessId - Default:
${processid}
- ProcessName - Default:
${processname:FullName=false}
- ProcessTitle - Default:
${processinfo:MainWindowTitle}
- ProcessThreadId - Default:
${threadid}
- ProcessThreadName -
- ProcessExecutable - Default:
Server Options
- ServerAddress -
- ServerIp -
- ServerUser - Default:
${environment-user}
Host Options
- HostId -
- HostIp - Default:
${local-ip:cachedSeconds=60}
- HostName - Default:
${machinename}
Log Origin Options
- LogOriginCallSiteMethod - Default:
${exception:format=method}
- LogOriginCallSiteFile - Default:
${exception:format=source}
- LogOriginCallSiteLine -
- LogOriginCallSiteMethod - Default:
Http Options
- HttpRequestId - Default:
${aspnet-trace-identifier}
- HttpRequestMethod - Default:
${aspnet-request-method}
- HttpRequestBytes - Default:
${aspnet-request-contentlength}
- HttpRequestReferrer - Default:
${aspnet-request-referrer}
- HttpResponseStatusCode - Default:
${aspnet-response-statuscode}
- HttpRequestId - Default:
Url Options
- UrlScheme - Default:
${aspnet-request-url:IncludeScheme=true:IncludeHost=false:IncludePath=false}
- UrlDomain - Default:
${aspnet-request-url:IncludeScheme=false:IncludeHost=true:IncludePath=false}
- UrlPath - Default:
${aspnet-request-url:IncludeScheme=false:IncludeHost=false:IncludePath=true}
- UrlPort - Default:
${aspnet-request-url:IncludeScheme=false:IncludeHost=false:IncludePath=false:IncludePort=true}
- UrlQuery - Default:
${aspnet-request-url:IncludeScheme=false:IncludeHost=false:IncludePath=false:IncludeQueryString=true}
- UrlUserName - Default:
${aspnet-user-identity}
- UrlScheme - Default:
Trace Options
- ApmTraceId - Default:
${ElasticApmTraceId}
- ApmTraceId - Default:
Transaction Options
- ApmTransactionId - Default:
${ElasticApmTransactionId}
- ApmTransactionId - Default:
ECS Aware Message Templates
Additionally any valid ECS log template properties that is available under LogTemplateProperties.*
e.g LogTemplateProperties.TraceId
is supported and will directly set the appropriate ECS fields.
logger.Info("The time is {TraceId}", "my-trace-id");
Will override trace.id
on the resulting ECS json document.
Example output from EcsLayout
An example of the output is given below:
{
"@timestamp": "2020-02-20T16:07:06.7109766+11:00",
"log.level": "Info",
"message": "Info \"X\" 2.2",
"ecs.version": "8.6.0",
"log": {
"logger": "Elastic.CommonSchema.NLog.Tests.LogTestsBase",
},
"labels": {
"ValueX": "X",
"MessageTemplate": "Info {ValueX} {SomeY} {NotX}"
},
"agent": {
"type": "Elastic.CommonSchema.NLog",
"version": "1.6.0"
},
"event": {
"created": "2020-02-20T16:07:06.7109766+11:00",
"severity": 6,
"timezone": "Romance Standard Time"
},
"host": {
"ip": [ "127.0.0.1" ],
"name": "LOCALHOST"
},
"process": {
"executable": "C:\\Program Files\\dotnet\\dotnet.exe",
"name": "dotnet",
"pid": 17592,
"thread.id": 17592,
"title": "15.0.0.0"
},
"server": { "user": { "name": "MyUser" } },
"service": {
"name": "Elastic.CommonSchema",
"type": "dotnet",
"version": "1.6.0"
},
"metadata": {
"SomeY": 2.2
}
}
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.11.0)
- NLog (>= 4.7.15)
-
.NETStandard 2.0
- Elastic.CommonSchema (>= 8.11.0)
- NLog (>= 4.7.15)
-
.NETStandard 2.1
- Elastic.CommonSchema (>= 8.11.0)
- NLog (>= 4.7.15)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Elastic.CommonSchema.NLog:
Package | Downloads |
---|---|
Elastic.NLog.Targets
NLog Target that exports directly to Elastic Cloud or individual Elasticsearch nodes |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.12.3 | 54 | 11/26/2024 |
8.12.2 | 23,567 | 10/22/2024 |
8.12.1 | 9,482 | 10/3/2024 |
8.12.0 | 1,115 | 9/26/2024 |
8.11.1 | 111,379 | 6/10/2024 |
8.11.0 | 27,676 | 4/10/2024 |
8.6.1 | 252,138 | 8/3/2023 |
8.6.0 | 46,581 | 5/9/2023 |
8.4.0-alpha4 | 2,092 | 3/28/2023 |
8.4.0-alpha3 | 635 | 3/15/2023 |
8.4.0-alpha2 | 650 | 3/1/2023 |
8.4.0-alpha1 | 640 | 2/20/2023 |
1.6.0-alpha1 | 144,565 | 6/2/2021 |
1.5.3 | 422,133 | 6/1/2021 |
1.5.1 | 18,143 | 6/3/2020 |
1.5.0 | 1,483 | 3/30/2020 |
1.4.4 | 1,033 | 3/25/2020 |
1.4.3 | 1,097 | 3/16/2020 |
1.4.2 | 1,018 | 3/6/2020 |
1.4.1 | 2,332 | 2/26/2020 |