Serilog.Sinks.AzureLogAnalytics
6.7.0
dotnet add package Serilog.Sinks.AzureLogAnalytics --version 6.7.0
NuGet\Install-Package Serilog.Sinks.AzureLogAnalytics -Version 6.7.0
<PackageReference Include="Serilog.Sinks.AzureLogAnalytics" Version="6.7.0" />
paket add Serilog.Sinks.AzureLogAnalytics --version 6.7.0
#r "nuget: Serilog.Sinks.AzureLogAnalytics, 6.7.0"
// Install Serilog.Sinks.AzureLogAnalytics as a Cake Addin #addin nuget:?package=Serilog.Sinks.AzureLogAnalytics&version=6.7.0 // Install Serilog.Sinks.AzureLogAnalytics as a Cake Tool #tool nuget:?package=Serilog.Sinks.AzureLogAnalytics&version=6.7.0
Serilog.Sinks.AzureLogAnalytics
High performance Serilog sink that writes to Azure Log Analytics. It supports automatic batching of log messages for better performance and auto-recovery from transient errors.
Getting started
Install Serilog.Sinks.AzureLogAnalytics from NuGet
Install-Package Serilog
Install-Package Serilog.Settings.Configuration
Install-Package Serilog.Sinks.AzureLogAnalytics
Install-Package Microsoft.Extensions.Configuration.Json
Configure logger by calling WriteTo.AzureLogAnalytics(<credentials>, <configSettings>)
credentials
: A structure with required information to access Azure Log Ingestion API. to from Azure OMS Portal connected sources. This parameter accepts:
Parameter name | Meaning |
---|---|
endpoint |
Logs Ingestion URL for data collection endpoint. |
immutableId |
ImmutableId for Data Collection Rules (DCR). |
streamName |
Output stream name of target (Log Analytics API, can be accessed from DCR). |
tenantId |
Directory (tenant) Id of registered application (Microsoft Entra ID). |
clientId |
Application (client) Id of Microsoft Entra application. |
clientSecret |
Client secret for registered Entra Application. |
Log.Logger = new LoggerConfiguration()
.WriteTo.AzureLogAnalytics(<credentials>, <configSettings>)
.CreateLogger();
Formatting event JSON
To adjust the format of the event JSON populated into Azure Log Analytics, pass an ITextFormatter
as the first argument:
Log.Logger = new LoggerConfiguration()
.WriteTo.AzureLogAnalytics(new CompactJsonFormatter(), <credentials>, <configSettings>)
.CreateLogger();
JSON appsettings configuration
In your appsettings.json
file, configure following:
{
"Serilog": {
"Using": [ "Serilog.Sinks.AzureLogAnalytics" ],
"MinimumLevel": "Verbose",
"WriteTo": [
{
"Name": "AzureLogAnalytics",
"Args": {
"credentials": {
"endpoint": "https://****.****.ingest.monitor.azure.com",
"immutableId": "dcr-****",
"streamName": "Custom-****_CL",
"tenantId": "****-****-****-****-****",
"clientId": "****-****-****-****-****",
"clientSecret": "*******"
},
"configSettings": {
"bufferSize": "5000",
"batchSize": "100"
}
}
}
]
}
}
To configure and instanciate AzureLogAnalytics sink in appsettings.json
, in your code, call:
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json").Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
Tutorial: Send data to Azure Monitor Logs with Logs ingestion API (Azure portal) is good resource to configure environment for Log Ingestion API in Azure portal.
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 is compatible. 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 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 | 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. |
-
.NETStandard 2.0
- Azure.Core (>= 1.44.1)
- Microsoft.CSharp (>= 4.7.0)
- Serilog (>= 4.1.0)
- System.Net.Http (>= 4.3.4)
- System.Net.Http.Json (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
-
net8.0
- Azure.Core (>= 1.44.1)
- Microsoft.CSharp (>= 4.7.0)
- Serilog (>= 4.1.0)
- System.Net.Http (>= 4.3.4)
- System.Net.Http.Json (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.