Dependency injection & ILogger
Dependency injection & ILogger in the .NET SDK.
| Symbol | Kind | Summary |
|---|---|---|
NexusLoggerProvider | class | An ILogger provider that writes to the Nexus logs product. |
NexusLoggingOptions | class | Controls what the NexusLoggerProvider forwards. |
NexusServiceCollectionExtensions | static class | Registers the Nexus client in a dependency-injection container. |
NexusLoggerProvider
class Inverge.Nexus.Extensions.Loggingclass Inverge.Nexus.Extensions.Logging.NexusLoggerProviderAn ILogger provider that writes to the Nexus logs product.
Register it with builder.Logging.AddNexus(). Every existing
logger.LogInformation(...) in the application then lands in Nexus with no
call-site changes, and records carrying an exception also become grouped issues
in error monitoring.
NexusLoggerProvider
constructornew NexusLoggerProvider(IServiceProvider services, IOptions<NexusLoggingOptions> options)Creates the provider.
Parameters
Prop
Type
CreateLogger()
methodILogger CreateLogger(string categoryName)Parameters
Prop
Type
Returns ILogger
Dispose()
methodvoid Dispose()Releases the provider's loggers.
The client is not disposed here. It is a container singleton with its own lifetime, and the logging provider is usually torn down first — disposing it from here would stop telemetry while the rest of the application is still shutting down and still producing it.
SetScopeProvider()
methodvoid SetScopeProvider(IExternalScopeProvider scopeProvider)Parameters
Prop
Type
NexusLoggingOptions
class Inverge.Nexus.Extensions.Loggingclass Inverge.Nexus.Extensions.Logging.NexusLoggingOptionsControls what the NexusLoggerProvider forwards.
NexusLoggingOptions
constructornew NexusLoggingOptions()CaptureExceptions
propertybool CaptureExceptions { get; set; }Also report records that carry an exception to error monitoring, so a plain
logger.LogError(ex, ...) produces a grouped, stack-traced issue.
ExcludedCategoryPrefixes
propertystring[] ExcludedCategoryPrefixes { get; set; }Category prefixes never forwarded.
Inverge.Nexus is excluded unconditionally and is not listed here: the
SDK's own diagnostics must never become Nexus log lines, because delivering
them would produce more of them.
IncludeEventId
propertybool IncludeEventId { get; set; }Include the event id, when the call site set one.
IncludeScopes
propertybool IncludeScopes { get; set; }Include the active logging scopes in each line's context.
In ASP.NET Core this is what carries the request id and route into the log line, which is usually the difference between a searchable log and a wall of text.
MinimumLevel
propertyLogLevel MinimumLevel { get; set; }The lowest level forwarded to Nexus.
This is a second gate on top of the logging framework's own filters, so you
can keep Debug in the console while sending only Information and
above over the network — logs are billed per line.
NexusServiceCollectionExtensions
static class Inverge.Nexus.Extensions.Loggingstatic class Inverge.Nexus.Extensions.Logging.NexusServiceCollectionExtensionsRegisters the Nexus client in a dependency-injection container.
| Constant | Description |
|---|---|
const string DefaultConfigurationSection = "Nexus" | The configuration section bound by default. |
const string HttpClientName = "Inverge.Nexus" | The named HttpClient the SDK sends through. |
AddNexus()
extension methodstatic IServiceCollection AddNexus(IServiceCollection services, Action<NexusOptions>? configure = null, string? configurationSection = "Nexus")Registers INexusClient as a singleton.
Options are read from the Nexus configuration section first, then the
NEXUS_* environment, then configure. Code wins over
the environment, and the environment wins over appsettings — so a container
can be re-keyed or retuned without a rebuild.
The client sends through a named IHttpClientFactory client, so the
application's own handlers, resilience policies and connection lifetime apply.
A hosted service flushes buffered telemetry on shutdown.
Parameters
Prop
Type
Returns IServiceCollection
AddNexus()
extension methodstatic IServiceCollection AddNexus(IServiceCollection services, Action<NexusOptions>? configure, Action<NexusLoggingOptions>? configureLogging, string? configurationSection = "Nexus")Registers the client and forwards ILogger records to Nexus in one call.
Parameters
Prop
Type
Returns IServiceCollection
AddNexus()
extension methodstatic ILoggingBuilder AddNexus(ILoggingBuilder builder, Action<NexusLoggingOptions>? configure = null)Forwards ILogger records to the Nexus logs product, and records
carrying an exception to error monitoring.
Call AddNexus
as well — this adds the bridge, not the client it writes through.
Parameters
Prop
Type
Returns ILoggingBuilder
