Serilog.Sinks.Http.LogzIo
2.0.0
Please update to Serilog.Sinks.Logz.Io. Latest version contains exact the same functionality and extension methods to configure loggers.
See the version list below for details.
dotnet add package Serilog.Sinks.Http.LogzIo --version 2.0.0
NuGet\Install-Package Serilog.Sinks.Http.LogzIo -Version 2.0.0
<PackageReference Include="Serilog.Sinks.Http.LogzIo" Version="2.0.0" />
paket add Serilog.Sinks.Http.LogzIo --version 2.0.0
#r "nuget: Serilog.Sinks.Http.LogzIo, 2.0.0"
// Install Serilog.Sinks.Http.LogzIo as a Cake Addin #addin nuget:?package=Serilog.Sinks.Http.LogzIo&version=2.0.0 // Install Serilog.Sinks.Http.LogzIo as a Cake Tool #tool nuget:?package=Serilog.Sinks.Http.LogzIo&version=2.0.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
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.
NOTE: under the hood library uses DurableHttpUsingTimeRolledBuffers extension method to configure durable HTTP sink.
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"
}
}
}
]
}
}
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,
IncludeMessageTemplate = true,
LowercaseLevel = true
})
.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 | Versions 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. |
-
.NETFramework 4.6.1
- Elastic.CommonSchema.Serilog (>= 1.5.3)
- Newtonsoft.Json (>= 13.0.1)
- Serilog.Sinks.Http (>= 7.2.0)
- Serilog.Sinks.PeriodicBatching (>= 2.3.0)
-
.NETStandard 2.0
- Elastic.CommonSchema.Serilog (>= 1.5.3)
- Newtonsoft.Json (>= 13.0.1)
- Serilog.Sinks.Http (>= 7.2.0)
- Serilog.Sinks.PeriodicBatching (>= 2.3.0)
-
net5.0
- Elastic.CommonSchema.Serilog (>= 1.5.3)
- Newtonsoft.Json (>= 13.0.1)
- Serilog.Sinks.Http (>= 7.2.0)
- Serilog.Sinks.PeriodicBatching (>= 2.3.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Serilog.Sinks.Http.LogzIo:
Package | Downloads |
---|---|
Hive.Logging.LogzIo
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
* Switch to Newtonsoft.Json serializer