Serilog.Sinks.Logz.Io 5.1.0

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

// Install Serilog.Sinks.Logz.Io as a Cake Tool
#tool nuget:?package=Serilog.Sinks.Logz.Io&version=5.1.0                

A Serilog sink sending log events over HTTP to logz.io

Even though Serilog.Sinks.Logz.Io was original implementation I would strongly recommend to use Serilog.Sinks.Http.LogzIo. It uses a buffered file before sending to logz.io, which means that log entries won't be lost in case of connectivity issues and will be resend when connection is restored.

Available Packages

Serilog.Sinks.Logz.Io

NuGet Version NuGet Documentation Join the chat at https://gitter.im/serilog/serilog Help

Package - Serilog.Sinks.Logz.Io | Platforms - .NET 4.6.1, .NET Standard 2.0, NET 5.0

Installation

If you want to include the HTTP sink in your project, you can install it directly from NuGet.

To install the sink, run the following command in the Package Manager Console:

PM> Install-Package Serilog.Sinks.Logz.Io

Serilog.Sinks.Http.LogzIo

This package has been deprecated as it is legacy and is no longer maintained. Please update to Serilog.Sinks.Logz.Io. Latest version contains exact the same functionality and extension methods to configure loggers.

Usage

In the following example, the sink will POST log events to https://listener-eu.logz.io:8071/?type=app&token=<token> over HTTP. We configure the sink using named arguments instead of positional because historically we've seen that most breaking changes where the result of a new parameter describing a new feature. Using named arguments means that you more often than not can migrate to new major versions without any changes to your code.

Used in conjunction with Serilog.Settings.Configuration the same sink can be configured in the following way:

{
  "Serilog": {
    "MinimumLevel": "Warning",
    "WriteTo": [
      {
        "Name": "LogzIoDurableHttp",
        "Args": {
          "requestUri": "https://listener-eu.logz.io:8071/?type=app&token=<token>"
        }
      }
    ]
  }
}

The sink will be configured as durable, i.e. log events are persisted on disk before being sent over the network, thus protected against data loss after a system or process restart. For more information please read the wiki.

NOTE1: under the hood library uses DurableHttpUsingTimeRolledBuffers extension method to configure durable HTTP sink.

See: DurableHttpUsingTimeRolledBuffers

Wiki: Durable time rolled HTTP sink

NOTE2: there is a special handling for MulticastDelegate type (basically objects containing Func or Action properties).

Delegate serialization usually involves a lot of unecessary details so it was reduced a lot.

In order to disable this behavior you can change serializer settings: LogzIoSerializer.Instance = new LogzIoSerializer(LogzIoTextFormatterFieldNaming.CamelCase, false);

This place also can be used to change serialization options or set a custom serializer.

More advanced examples

NOTE: in example bellow only requestUri is required. All other properties represents default values.

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft.AspNetCore": "Debug"
      }
    },
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
    "WriteTo": [
      {
        "Name": "LogzIoDurableHttp",
        "Args": {
          "requestUri": "https://listener-eu.logz.io:8071/?type=app&token=<token>",
          "bufferPathFormat": "Buffer-{Hour}.json",
          "bufferFileSizeLimitBytes": "104857600",
          "bufferFileShared": false,
          "retainedBufferFileCountLimit": 31,
          "batchPostingLimit": 1000,
          "period": null,
          "restrictedToMinimumLevel": "Minimum",
          "logzioTextFormatterOptions": {
            "BoostProperties": true,
            "LowercaseLevel": true,
            "IncludeMessageTemplate": true,
            "FieldNaming": "CamelCase",
            "EventSizeLimitBytes": 261120
          }
        }
      }
    ]
  }
}

In the example above logzIo formatter options are default, there is no need to specify these if it fits your needs.

  • BoostProperties: When true, does not add 'properties' prefix.
  • LowercaseLevel: Set to true to push log level as lowercase.
  • IncludeMessageTemplate: When true the message template is included in the logs.
  • FieldNaming: allows to transform field names, possible values: null (default), CamelCase, LowerCase

Configuration from code

    configuration
        .WriteTo.LogzIoDurableHttp(
            "https://listener-eu.logz.io:8071/?type=app&token=<token>",
            logzioTextFormatterOptions: new LogzioTextFormatterOptions
            {
                BoostProperties = true,
                LowercaseLevel = true,
                IncludeMessageTemplate = true,
                FieldNaming = LogzIoTextFormatterFieldNaming.CamelCase,
                EventSizeLimitBytes = 261120,
            })
        .MinimumLevel.Verbose();

Logs without buffered file

NOTE: it is strongly recommended to use durable logger. It is much more robust and tollerates various network issues thus your logs won't be lost.

In the following example, the sink will POST log events to https://listener.logz.io over HTTPS.

ILogger log = new LoggerConfiguration()
  .MinimumLevel.Verbose()
  .WriteTo.LogzIo("<logzio token>", "<log type>", useHttps: true)
  .CreateLogger();

log.Information("Logging {@Heartbeat} from {Computer}", heartbeat, computer);

More advanced configuration is also available:

ILogger log = new LoggerConfiguration()
  .MinimumLevel.Verbose()
  .WriteTo.LogzIo("<logzio token>", "<log type>",
    new LogzioOptions 
    { 
        UseHttps = true, 
        RestrictedToMinimumLevel = LogEventLevel.Debug,
        Period = TimeSpan.FromSeconds(15),
        BatchPostingLimit = 50
    })
  .CreateLogger();

Alternatively configuration can be done within your appsettings.json file:

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Verbose"
    },
    "WriteTo": [
      {
        "Name": "LogzIo",
        "Args": {
          "authToken": "<logzio token>",
          "type": "<log type>",
          "dataCenterSubDomain": "listener",
          "useHttps": true,
          "batchPostingLimit": 5000,
          "period": "00:00:02",
          "restrictedToMinimumLevel": "Debug",
          "lowercaseLevel": false,
          "environment": "",
          "serviceName": ""
        }
      }
    ]
  }
}

Elastic Common Schema support

See for more details: https://www.elastic.co/guide/en/ecs/current/ecs-reference.html

ILogger log = new LoggerConfiguration()
  .MinimumLevel.Verbose()
  .WriteTo.LogzIo(new LogzioEcsOptions
        {
            Type = "<log type>",
            AuthToken = "<logzio token>",
            DataCenter = new LogzioDataCenter
            {
                SubDomain = "listener",
                Port = 8701,
                UseHttps = true
            }
        },
        batchPostingLimit: 50,
        period: TimeSpan.FromSeconds(15),
        restrictedToMinimumLevel: LogEventLevel.Debug
    )
  .CreateLogger();

Alternatively configuration can be done within your appsettings.json file, please note CustomEcsTextFormatterConfiguration setup is optional:

{
  "Serilog": {
    "Using": [
      "Serilog.Sinks.Console",
      "Serilog.Sinks.Logz.Io"
    ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Information",
        "System": "Warning"
      }
    },
    "WriteTo": [
      { "Name": "Console" },
      {
        "Name": "LogzIoEcs",
        "Args": {
          "options": {
            "type": "<log type>",
            "authToken": "<logzio token>"
          },
          "batchPostingLimit": 30,
          "period": "00:00:02",
          "restrictedToMinimumLevel": "Debug",
          "formatterConfiguration": "Serilog.Sinks.Logz.Io.AspNetCoreApi.Logging.CustomEcsTextFormatterConfiguration, Serilog.Sinks.Logz.Io.AspNetCoreApi"
        }
      }
    ]
  }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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 was computed. 
.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 (2)

Showing the top 2 NuGet packages that depend on Serilog.Sinks.Logz.Io:

Package Downloads
AlbaLogger

Package Description

AllbatrossLogger

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.2.0 339,441 12/12/2022
7.1.0 63,554 10/12/2022
7.0.0 6,965 10/12/2022
6.0.0 567,837 11/14/2021
5.1.0 22,898 10/2/2021
5.0.0 23,099 9/25/2021
3.0.1 93,203 2/9/2021
3.0.0 752 2/9/2021
2.3.0 94,179 10/30/2020
2.2.3 10,656 10/1/2020
2.2.2 82,118 4/16/2020
2.2.1 93,761 12/26/2018
2.2.0 2,565 12/20/2018
2.1.2 1,242 12/17/2018
2.1.1 4,346 10/17/2018
2.1.1-alpha.1 470 10/16/2018
2.1.0 908 10/10/2018
2.0.0 5,786 5/21/2018
1.2.4 1,193 5/16/2018
1.2.3 3,133 3/15/2018
1.2.2 1,109 3/13/2018
1.1.1 2,392 3/4/2018
1.1.0 1,064 3/4/2018
1.0.0 1,211 3/1/2018

* Switch to Newtonsoft.Json serializer