AStarDev.LoggingOTel
2.1.1
dotnet add package AStarDev.LoggingOTel --version 2.1.1
NuGet\Install-Package AStarDev.LoggingOTel -Version 2.1.1
<PackageReference Include="AStarDev.LoggingOTel" Version="2.1.1" />
<PackageVersion Include="AStarDev.LoggingOTel" Version="2.1.1" />
<PackageReference Include="AStarDev.LoggingOTel" />
paket add AStarDev.LoggingOTel --version 2.1.1
#r "nuget: AStarDev.LoggingOTel, 2.1.1"
#:package AStarDev.LoggingOTel@2.1.1
#addin nuget:?package=AStarDev.LoggingOTel&version=2.1.1
#tool nuget:?package=AStarDev.LoggingOTel&version=2.1.1
AStarDev.LoggingOTel
OpenTelemetry logging configuration helper: console exporter + Azure Monitor (Application Insights) log exporter + optional OTLP exporter, driven by IConfigurationRoot.
Installation
dotnet add package AStarDev.LoggingOTel
Or via the NuGet Package Manager in Visual Studio / Rider.
Available extensions
ILoggingBuilder.ConfigureOTelLogging(configuration, serviceName, connectionStringConfigurationKey = "ApplicationInsights:ConnectionString")
Wires up OpenTelemetry logging that:
- writes to the console
- exports to Azure Monitor when a connection string is present at
connectionStringConfigurationKeyin the suppliedIConfigurationRoot - exports over OTLP (gRPC) when
OpenTelemetry:OtlpEndpoint(OTelLoggingConfigurator.OtlpEndpointConfigurationKey) holds an absolutehttp/httpsURI, e.g.http://localhost:4317for the Aspire dashboard - includes formatted messages, scopes, and structured state values
- copies a failed operation's
ErrorTypeorExceptionTypeattribute to the semantic-convention keyerror.type(ErrorTypeLogProcessor, added before every exporter; a blank value becomes_OTHER, and records without either attribute get noerror.type) - sets the OpenTelemetry resource:
service.name(required; a blank value falls back to the entry assembly name),service.version(the entry assembly informational version without+build metadata), an auto-generatedservice.instance.id, anddeployment.environment.namefromOpenTelemetry:DeploymentEnvironment(OTelLoggingConfigurator.DeploymentEnvironmentConfigurationKey), else theDOTNET_ENVIRONMENTenvironment variable, elseproduction, lower-cased
An overload additionally accepts an InMemoryLogProcessor, routing log records to it as well — used for the in-app log viewer feature (AStarDev.LoggingOTel.LogViewer).
Build
This package lives inside the astar-dev-mono mono-repo and inherits all build configuration from the root Directory.Build.props.
# From the repo root — builds everything
dotnet build
# Build only this package
dotnet build packages/core/logging/AStarDev.LoggingOTel
# If Directory.Build.props changes aren't being picked up
dotnet clean && dotnet build packages/core/logging/AStarDev.LoggingOTel
Test
Tests for this package live alongside it in AStarDev.LoggingOTel.TestsUnit.
# Run all tests
dotnet test
# Run tests for this package specifically
dotnet test packages/core/logging/AStarDev.LoggingOTel.TestsUnit
Contributing
- Fork the repo and create a branch:
feat/logging-otel-<short-description>orfix/logging-otel-<short-description>. - Follow the Conventional Commits format — e.g.
feat(packages/core/logging/AStarDev.LoggingOTel): add XyzExtensions. - All warnings are treated as errors (
TreatWarningsAsErrors=true), so the build must stay clean. - Add or update the relevant doc file under
docs/if you add a new extension or change an existing one. - Open a PR against
main. CI runs automatically on push.
Do not run dotnet pack or dotnet nuget push manually — releases are triggered by pushing a v* tag. See the repo-level Releasing a new version guide.
Metrics and traces
OTelTelemetryConfigurator.ConfigureOTelTelemetry(configuration, serviceName, meterName, activitySourceName) starts exporting one meter and one activity source, for applications that are not hosted by the generic host. It exports to the OTLP endpoint (OpenTelemetry:OtlpEndpoint) and to Azure Monitor (ApplicationInsights:ConnectionString) when they are configured. Dispose the returned TelemetryProviders to flush.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Azure.Monitor.OpenTelemetry.Exporter (>= 1.10.0)
- Microsoft.Extensions.Configuration (>= 10.0.12)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.12)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.12)
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.12)
- Microsoft.Extensions.Configuration.Json (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Options (>= 10.0.12)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.12)
- Microsoft.Identity.Client (>= 4.90.1)
- Microsoft.Identity.Client.Extensions.Msal (>= 4.90.1)
- OpenTelemetry (>= 1.19.1)
- OpenTelemetry.Api (>= 1.19.1)
- OpenTelemetry.Exporter.Console (>= 1.19.1)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.19.1)
- System.Reactive (>= 7.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AStarDev.LoggingOTel:
| Package | Downloads |
|---|---|
|
AStarDev.LoggingExtensions
This package contains extension methods designed to add OpenTelemetry logging, tracing, and metrics, exported to Azure Monitor (Application Insights), to the project. The logging is opinionated but the configuration can be overridden. |
GitHub repositories
This package is not used by any popular GitHub repositories.
v2.1.1 build: enable EnforceCodeStyleInBuild centrally (#1941)
v2.1.0 feat(cloudsync): OpenTelemetry metrics and traces for startup and overview refresh
v2.0.1 refactor(logging): drop InternalsVisibleTo from LoggingOTel (#1417)
v2.0.0 chore(logging)!: remove the always-null LogEntry.AccountId (#1388)
v1.1.0 feat(logging): export error.type on failed operations (#1374)
v1.0.0 feat(logging)!: complete the OTel resource (service.version, instance id, deployment environment) (#1370)
v0.2.0 feat(cloudsync): send logs to the Aspire dashboard (OTLP) and Application Insights
v0.1.2 fix: set the OpenTelemetry service.name so logs are not reported as unknown_service (#527)
v0.1.1 chore: promote IDE0058 to warning
v0.1.0 Rename infrastructure/ to packages/ and add fully automatic NuGet release pipeline
v0.1.0 Initial release.