ToolsPack.Logging.Otlp
0.1.0
dotnet add package ToolsPack.Logging.Otlp --version 0.1.0
NuGet\Install-Package ToolsPack.Logging.Otlp -Version 0.1.0
<PackageReference Include="ToolsPack.Logging.Otlp" Version="0.1.0" />
<PackageVersion Include="ToolsPack.Logging.Otlp" Version="0.1.0" />
<PackageReference Include="ToolsPack.Logging.Otlp" />
paket add ToolsPack.Logging.Otlp --version 0.1.0
#r "nuget: ToolsPack.Logging.Otlp, 0.1.0"
#:package ToolsPack.Logging.Otlp@0.1.0
#addin nuget:?package=ToolsPack.Logging.Otlp&version=0.1.0
#tool nuget:?package=ToolsPack.Logging.Otlp&version=0.1.0
ToolsPack.Logging.Oltp
In the current .NET OLTP (v1.10.0) implementation, the
LogRecord
class
is not serializable.
It contains a lot of interesting OpenTelemetry information, mixing with other logics.
IMO, actual implementation of this class should rather be called LogRecordKitchenSink
than LogRecord
.
This nuget library provides a mapping of the LogRecord
"kitchen sink" object to a serializable
LogRecordDto
object:
Checkout the LogRecordConverter
class.
It should facilitate you to develop your own custom exporter (File, Console...).
The library also provides simple implementation of Console and File exporter which will format the telemetry log records to json.
Log to Console
using System.Diagnostics;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using ToolsPack.Logging.Otlp;
var resourceBuilder = ResourceBuilder.CreateDefault().AddService("my-service");
ActivitySource activitySource = new("LogScopeTests", "1.0.0");
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(resourceBuilder)
.AddSource("LogScopeTests")
.Build();
var loggerFactory = LoggerFactory.Create(builder =>
builder.AddOpenTelemetry(options =>
{
options.SetResourceBuilder(resourceBuilder);
options.IncludeScopes = true;
options.IncludeFormattedMessage = true;
options.AddProcessor(new SimpleLogRecordExportProcessor /*or BatchLogRecordExportProcessor*/(
new JsonConsoleLogsExporter(exporterOptions =>
{
exporterOptions.JsonSerializerOptions.IndentSize = 2;
exporterOptions.JsonSerializerOptions.WriteIndented = true;
})
));
})
);
var logger = loggerFactory.CreateLogger("G");
using (activitySource.StartActivity())
{
logger.LogInformation("Hello {thing}!", "World");
}
/*
{
"timestamp": "2024-12-31T20:43:40.8521675Z",
"traceId": "f8c7dc7c4fee9f0dfb2a1c2a42a08c84",
"spanId": "52e69b4fb2fbde5f",
"traceFlags": 1,
"categoryName": "G",
"severity": 2,
"formattedMessage": "Hello World!",
"eventId": {
"id": 0
},
"body": "Hello {thing}!",
"attributes": {
"thing": "World",
"{OriginalFormat}": "Hello {thing}!"
},
"scopeValues": [],
"resource": {
"service.name": "my-service",
"service.instance.id": "c983b8ce-cdf4-4cb0-8da6-b30ba6192ca6",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.language": "dotnet",
"telemetry.sdk.version": "1.10.0"
}
}
*/
Log to file
using Microsoft.Extensions.Logging;
using OpenTelemetry;
var loggerFactory = LoggerFactory.Create(builder =>
builder.AddOpenTelemetry(options =>
{
options.AddProcessor(new SimpleLogRecordExportProcessor /*or BatchLogRecordExportProcessor*/(
new JsonFileLogsExporter(exporterOptions => {
exporterOptions.FilePath = "./app.log";
})
));
})
);
var logger = loggerFactory.CreateLogger("G");
logger.LogInformation("Hello World");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- OpenTelemetry (>= 1.10.0)
-
net7.0
- OpenTelemetry (>= 1.10.0)
-
net8.0
- OpenTelemetry (>= 1.10.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
0.1.0 | 128 | 12/31/2024 |