CB.Serilog.Sinks.AzureLogAnalytics
1.0.1
See the version list below for details.
dotnet add package CB.Serilog.Sinks.AzureLogAnalytics --version 1.0.1
NuGet\Install-Package CB.Serilog.Sinks.AzureLogAnalytics -Version 1.0.1
<PackageReference Include="CB.Serilog.Sinks.AzureLogAnalytics" Version="1.0.1" />
paket add CB.Serilog.Sinks.AzureLogAnalytics --version 1.0.1
#r "nuget: CB.Serilog.Sinks.AzureLogAnalytics, 1.0.1"
// Install CB.Serilog.Sinks.AzureLogAnalytics as a Cake Addin #addin nuget:?package=CB.Serilog.Sinks.AzureLogAnalytics&version=1.0.1 // Install CB.Serilog.Sinks.AzureLogAnalytics as a Cake Tool #tool nuget:?package=CB.Serilog.Sinks.AzureLogAnalytics&version=1.0.1
Serilog Sink for Azure Log Analytics
A bare bones custom Serilog sink for Azure Log Analytics. Supports batching of logs. Utilizes the Azure.Monitor.Ingestion
library for ingestion to Log Analytics.
Prerequisites
- Azure Subscription
- Log Analytics workspace provisioned
- A configured data collection endpoint and data collection rule in Azure with appropriate permissions.
Get Started
Install package
dotnet add package CB.Serilog.Sinks.AzureLogAnalytics
Authenticate with Azure
By default, a DefaultAzureCredential is used to authenticate with Azure and no additional code is needed. Optionally, a TokenCredential
can be passed in for use.
Configure
The sink can be configured programatticaly or through Serilog Serilog.Settings.Configuration
NuGet package. An instance of AzureLogAnalyticsSinkConfiguration
is required.
App Config Example
program.cs
Host.CreateDefaultBuilder()
.UseSerilog((hostingContext, services, loggerConfiguration) =>
{
var assemblies = new[] { typeof(AzureLogAnalyticsSink).Assembly };
var options = new ConfigurationReaderOptions(assemblies);
loggerConfiguration
.Enrich.FromLogContext()
.ReadFrom.Configuration(hostingContext.Configuration, options);
});
app.config.json
"Serilog": {
"Using": [ "Serilog.Sinks.AzureLogAnalytics" ],
"MinimumLevel": "Verbose",
"WriteTo": [
{
"Name": "AzureLogAnalytics",
"Args": {
"DataCollectionEndpointUri": "<data-collection-endpoint>",
"RuleId": "<rule-id>",
"StreamName": "<stream-name>",
"OutputToConsole": true,
"MaxLogEntries": 5
}
}
]
}
IHostBuilder Example
program.cs
Host.CreateDefaultBuilder()
.UseSerilog((hostingContext, services, loggerConfiguration) =>
{
loggerConfiguration
.Enrich.FromLogContext()
.WriteTo.AzureLogAnalytics(new AzureLogAnalyticsSinkConfiguration
{
DataCollectionEndpointUri = new Uri("<data-collection-endpoint>"),
MaxLogEntries = 10,
RuleId = "<rule-id>",
StreamName = "<stream-name>",
OutputToConsole = true,
TokenCredential = "optional token credential"
})
});
The AzureLogAnalyticsSinkConfiguration
type is used to configure the sink.
Property | Description |
---|---|
DataCollectionEndpointUri | The data collection endpoindt setup in Azure |
MaxLogEntries | The maximum number of log entries to buffer before flushing to Log Analytics |
RuleId | The data collection rule id setup in Azure |
StreamName | The data collection rule stream name (your custom log analytics table |
OutputToConsole | An optional feature that outputs log output to the console. This is useful when configuring your data collection rule schema and transformation. |
TokenCredential | An instance of TokenCredential used to authenticate with Azure. This is optional. By default an DefaultAzureCredential is used. |
Transform | An optional Func<LogEvent, IDictionary<string, object>> to transform a Serilog LogEvent to an IDictionary<string, object> that will be serialized to Json to be sent to Log Analytics. A default implementation is provided if not set. Note: This method should be thread-safe, as it will be called concurrently by Serilog. |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- Azure.Identity (>= 1.10.4)
- Azure.Monitor.Ingestion (>= 1.1.1)
- Serilog (>= 3.1.1)
- Serilog.Settings.Configuration (>= 8.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.
Initial Release