Logging provider common implementations for Nano applications.
⚠️ This NuGet is transitive and included in other Nano Packages, and is not meant to be included directly.
Enabling logging in a Nano application is done by adding a logging provider.
When a provider is registered, Nano automatically registers the following interfaces during application startup:
ILoggerFactoryILoggerILogger<T>
All logging providers write to the console by default.
In Staging and Production environments, Kubernetes agents intercept STDOUT and STDERR and stream logs into centralized logging. It is recommended
to let the log collector handle log storage and routing, rather than configuring individual applications.
If no logging provider is registered, a NullLogger is used. This means ILogger and ILogger<T> will resolve correctly,
but all logs are discarded. Similarly, ILoggerFactory is available but produces no output.
To enable logging, the logging provider must be registered.
Use the AddNanoLogging<TProvider>() method, specifying your logging provider implementation as the generic type parameter.
...
.ConfigureServices(services =>
{
services
.AddNanoLogging<TProvider>();
})
...The Logging section in the configuration defines the logging provider and related settings used by the application.
| Setting | Type | Default | Description |
|---|---|---|---|
LogLevel |
enum | Information | The default minimum LogLevel used by the logging provider. Values: Debug, Information, Warning, Error, Fatal. |
LogLevelOverrides |
array | [] | Optional overrides for specific namespaces, allowing different log levels for different parts of the application. |
LogLevelOverrides.Namespace |
string | null | The log level to apply for a specific namespace. You may prepend an asterisk (*) as a wildcard to match multiple namespaces. |
LogLevelOverrides.LogLevel |
enum | Warning | The namespace for which this log level override applies. Values: Debug, Information, Warning, Error, Fatal. |
"Logging": {
"LogLevel": "Information",
"LogLevelOverrides":
[
{
"Namespace": "Microsoft",
"LogLevel": "Warning"
}
]
}📖 Learn more about Application Configuration here.
Nano provides several logging providers, so usually there is no need to implement a custom 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.
To create a new logging provider, implement the ILoggingProvider interface. Make sure to register all required services in the Configure method,
and then register your provider with the application using .AddNanoLogging<TProvider>().
The following logging providers are currently supported in Nano.