Skip to content

Logging

Michael Vivet edited this page Apr 24, 2022 · 33 revisions

Table of Contents


Summary

Nano registers the interfaces ILogger and ILogger<T> during application startup.

The ILoggingProvider is registered during startup, and the implementing type defines the logging provider used in the application.


Configuration

The Logging section of the configuration defines the behavior and severity of logging in the application.

The section is serialized into an instance of LoggingOptions, and injected as dependency during startup, thus available for injection throughout the application.

See Appendix - App Settings - Logging for details about the section and the meaning of the variables.

Logging Section
"Logging": {
  "LogLevel": "Information",
  "LogLevelOverrides": 
  [
      {
        "Namespace": "System",
        "LogLevel": "Debug"
      }
    ]
}

Logging Provider

Nano provides several logging providers (and more added on request), so usually there is no need to implement a custom data provider for your application.

Logging providers implements the interface ILoggingProvider. It contains a single method Configure(...), that is responsible for handling any configuration and setup required for the logging provider.

The logging providers currently supported by Nano, can be referenced in the Appendix - Supported Providers.


Logging Registration

The logging provider must be registered as dependencies. Invoke the method .AddLogging<TProvider>(), using the logging provider implementation as generic type parameters.

Sample Implementation
.ConfigureServices(x =>
{
    x.AddLogging<SerilogProvider>();
})

Injected Services

When building the logging provider, dependencies related to the logging is configured and initialized.

Dependencies:
  • Nano.Logging.LoggingOptions
  • Nano.Logging.Interfaces.ILoggingProvider

For a full list of services and dependencies, see Injected Dependencies