Logzio.DotNet.NLog 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Logzio.DotNet.NLog --version 1.1.1                
NuGet\Install-Package Logzio.DotNet.NLog -Version 1.1.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="Logzio.DotNet.NLog" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Logzio.DotNet.NLog --version 1.1.1                
#r "nuget: Logzio.DotNet.NLog, 1.1.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 Logzio.DotNet.NLog as a Cake Addin
#addin nuget:?package=Logzio.DotNet.NLog&version=1.1.1

// Install Logzio.DotNet.NLog as a Cake Tool
#tool nuget:?package=Logzio.DotNet.NLog&version=1.1.1                

Logz.io NLog Target

Install the NLog target from the Package Manager Console:

Install-Package Logzio.DotNet.NLog

If you prefer to install the library manually, download the latest version from the releases page.

Configuration

XML

If you configure your logging in an XML file, you need to register the assembly and then reference the target.

<nlog>
    <extensions>
	<add assembly="Logzio.DotNet.NLog"/>
    </extensions>
    <targets>
	

	<target name="logzio" type="Logzio"
		token="<<SHIPPING-TOKEN>>"
		logzioType="nlog"
		listenerUrl="<<LISTENER-HOST>>:8071"
                
		bufferSize="100"
		bufferTimeout="00:00:05"
		retriesMaxAttempts="3"
		retriesInterval="00:00:02"
		includeEventProperties="true"
		useGzip="false"
		debug="false"
		debugLogFile="my_absolute_path\debug.txt"
		jsonKeysCamelCase="false"
		addTraceContext="false"
		
                
	>
		<contextproperty name="host" layout="${machinename}" />
		<contextproperty name="threadid" layout="${threadid}" />
	</target>
    </targets>
    <rules>
	<logger name="*" minlevel="Info" writeTo="logzio" />
    </rules>
</nlog>

Code

To add the Logz.io target via code, add the following lines:

var config = new LoggingConfiguration();

// Replace these parameters with your configuration
var logzioTarget = new LogzioTarget {
    Name = "Logzio",
    Token = "<<SHIPPING-TOKEN>>",
    LogzioType = "nlog",
    ListenerUrl = "<<LISTENER-HOST>>:8071",
    BufferSize = 100,
    BufferTimeout = TimeSpan.Parse("00:00:05"),
    RetriesMaxAttempts = 3,
    RetriesInterval = TimeSpan.Parse("00:00:02"),
    Debug = false,
    DebugLogFile = "my_absolute_path_to_file",
    JsonKeysCamelCase = false,
    AddTraceContext = false,
    // ParseJsonMessage = true, 
    // ProxyAddress = "http://your.proxy.com:port",
    // UseStaticHttpClient = true,
};

config.AddRule(LogLevel.Debug, LogLevel.Fatal, logzioTarget);
LogManager.Configuration = config;

Json Format

To parse your messages as Json add to the logger's configuration the field 'parseJsonMessage' with the value 'true' (or uncomment).
When using 'JsonLayout' set the name of the attribute to other than 'message'. for example:

<layout type="JsonLayout" includeAllProperties="true">
    <attribute name="msg"  layout="${message}" encode="false"/>
</layout>

Click here for more information about JsonLayout.

Context Properties

You can configure the target to include your own custom values when forwarding to Logzio. For example:

<nlog>
    <variable name="site" value="New Zealand" />
    <variable name="rings" value="one" />
    <target name="logzio" type="Logzio" token="<<SHIPPING-TOKEN>>" includeEventProperties="true" includeMdlc="false">
	<contextproperty name="site" layout="${site}" />
	<contextproperty name="rings" layout="${rings}" />
    </target>
</nlog>
  • includeEventProperties - Include NLog LogEvent Properties. Default=True
  • includeMdlc - Include NLog MDLC properties by configuring. Default=False

Notice that the resulting messeage can grow in size to the point where it exceeds the endpoint's capacity. Changing to 'includeEventProperties="false"' will reduce the size of the message being shipped. Alternative you can enable useGzip="true".

Extensibility

If you want to change some of the fields or add some of your own, inherit the target and override the ExtendValues method:

[Target("MyAppLogzio")]
public class MyAppLogzioTarget : LogzioTarget
{
    protected override void ExtendValues(LogEventInfo logEvent, Dictionary<string, string> values)
    {
	values["logger"] = "MyPrefix." + values["logger"];
	values["myAppClientId"] = new ClientIdProvider().Get();
    }
}

You will then have to change your configuration in order to use your own target.

Trace Context

WARNING: Does not support .NET Standard 1.3

If you’re sending traces with OpenTelemetry instrumentation (auto or manual), you can correlate your logs with the trace context. In this way, your logs will have traces data in it: span id and trace id. To enable this feature, set addTraceContext="true" in your configuration or AddTraceContext = true in your code (as shown in the previews sections).

Serverless platforms

If you’re using a serverless function, you’ll need to call the appender's flush method at the end of the function run to make sure the logs are sent before the function finishes its execution. You’ll also need to create a static appender in the Startup.cs file so each invocation will use the same appender. The appender should have the UseStaticHttpClient flag set to true.

Azure serverless function code sample

Startup.cs

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Logzio.DotNet.NLog;
using NLog;
using NLog.Config;
using System;

[assembly: FunctionsStartup(typeof(LogzioNLogSampleApplication.Startup))]

namespace LogzioNLogSampleApplication
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var config = new LoggingConfiguration();

            // Replace these parameters with your configuration
            var logzioTarget = new LogzioTarget
            {
                Name = "Logzio",
                Token = "<<LOG-SHIPPING-TOKEN>>",
                LogzioType = "nlog",
                ListenerUrl = "https://<<LISTENER-HOST>>:8071",
                BufferSize = 100,
                BufferTimeout = TimeSpan.Parse("00:00:05"),
                RetriesMaxAttempts = 3,
                RetriesInterval = TimeSpan.Parse("00:00:02"),
                Debug = false,
                JsonKeysCamelCase = false,
                AddTraceContext = false,
                UseStaticHttpClient = true, 
                // ParseJsonMessage = true,
                // ProxyAddress = "http://your.proxy.com:port"
            };

            config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, logzioTarget);
            LogManager.Configuration = config;
        }
    }
}

FunctionApp.cs

using System;
using Microsoft.Azure.WebJobs;
using NLog;
using Microsoft.Extensions.Logging;
using MicrosoftLogger = Microsoft.Extensions.Logging.ILogger;

namespace LogzioNLogSampleApplication
{
    public class TimerTriggerCSharpNLog
    {
        private static readonly Logger nLog = LogManager.GetCurrentClassLogger();

        [FunctionName("TimerTriggerCSharpNLog")]
        public void Run([TimerTrigger("*/30 * * * * *")]TimerInfo myTimer, MicrosoftLogger msLog)
        {
            msLog.LogInformation($"NLogzio C# Timer trigger function executed at: {DateTime.Now}");

            nLog.WithProperty("iCanBe", "your long lost pal")
                .WithProperty("iCanCallYou", "Betty, and Betty when you call me")
                .WithProperty("youCanCallMe", "Al")
                .Info("If you'll be my bodyguard");
            // Call Flush method before function trigger finishes
            LogManager.Flush(5000);
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net46 was computed.  net461 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 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 (4)

Showing the top 4 NuGet packages that depend on Logzio.DotNet.NLog:

Package Downloads
LagoVista.IoT.Logging

Provides Logging and Error Reporing Implementations for the LagoVista Devices, IoT and Home Automation Frameworks.

Logzio.NLog.Extensions

A logging extension to simplify configuration of Logzio's NLog package for sending log entries to Logz.io

Crossroads.Microservice.Logging

C# .Net library for boostrapping logging to align with Crossroads best practices.

Crossroads.Microservice.Logging.Upgraded

C# .Net library for boostrapping logging to align with Crossroads best practices. Upgrade to .NET 6

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Logzio.DotNet.NLog:

Repository Stars
Jericho/StrongGrid
Strongly typed library for the entire SendGrid v3 API, including webhooks
Version Downloads Last updated
1.2.0 18,962 5/27/2024
1.1.1 6,590 5/20/2024
1.1.0 62,032 10/23/2023
1.0.16 78,116 2/26/2023
1.0.15 6,805 2/15/2023
1.0.14 2,747 1/31/2023
1.0.13 271,989 9/14/2021
1.0.12 41,077 7/27/2021
1.0.11 22,557 5/24/2021
1.0.10 240,506 5/12/2020
1.0.9 27,671 2/5/2020
1.0.8 4,836 1/12/2020
1.0.7 298,244 9/8/2019
1.0.6 45,794 3/5/2019
1.0.5 728 2/24/2019
1.0.4 25,609 11/19/2018
1.0.3 34,164 9/3/2018
1.0.0 1,056 8/21/2018
0.21.0 3,355 8/7/2018
0.20.0 52,969 1/17/2017
0.3.0 849 8/21/2018
0.1.0 1,074 12/21/2016

Option to format message as json