Class TelemetryHub
Provides a standard global place where libraries and applications can gain access to the application's ActivitySource and LoggerFactory for recording traces and logs. Applications that enable tracing and logging and want to enable logging and tracing by Neon libraries set LoggerFactory and ActivitySource immediately after configuring telemetry using the OpenTelemetry and Microsoft.Extensions.Logging APIs.
note
The Neon.Service.NeonService class initializes these properties by default when used by applications based on this class.
CreateLogger<T>(LogAttributes, bool, bool), CreateLogger(Type, LogAttributes, bool, bool), or CreateLogger(string, LogAttributes, bool, bool) are helper methods for obtaining loggers.
You can also set the LogAttributes property to attributes you'd like to include
in the loggers returned by the CreateLogger()
methods. This is a handy way to include
a common set of attributes with all logged events.
The ParseLogLevel(string, LogLevel) utility can be used to parse a log level string obtained from an environment variable or elsewhere. This returns the parsed log level and also sets the Logging__LogLevel__Microsoft environment variable which will be honored by any created loggers.
Namespace: Neon.Diagnostics
Assembly: Neon.Common.dll
Syntax
public static class TelemetryHub
Properties
ActivitySource
Holds the global activity source used by Neon and perhaps other libraries for emitting
traces. This defaults to null
which means that libraries won't emit any
traces by default. Programs should set this after configuring tracing.
Declaration
public static ActivitySource ActivitySource { get; set; }
Property Value
Type | Description |
---|---|
ActivitySource |
LogAttributes
Optionally holds any LogAttributes that will be added to ILogger instances returned by CreateLogger(string, LogAttributes, bool, bool), CreateLogger(Type, LogAttributes, bool, bool), or CreateLogger<T>(LogAttributes, bool, bool).
Declaration
public static LogAttributes LogAttributes { get; set; }
Property Value
Type | Description |
---|---|
LogAttributes |
LoggerFactory
Holds the global ILoggerFactory used by the Neon and perhaps other libraries
for emitting logs. This defaults to null
which means that libraries won't emit any
logs by default. Programs should set this after configuring logging.
Declaration
public static ILoggerFactory LoggerFactory { get; set; }
Property Value
Type | Description |
---|---|
ILoggerFactory |
Methods
CreateLogger(string, LogAttributes, bool, bool)
Returns an ILogger using the category name passed.
Declaration
public static ILogger CreateLogger(string categoryName, LogAttributes attributes = null, bool noAttributes = false, bool nullLogger = false)
Parameters
Type | Name | Description |
---|---|---|
string | categoryName | Specifies the logger's category name. |
LogAttributes | attributes | Optionally specifies attributes to be included in every event logged. |
bool | noAttributes | Optionally indicates that the LogAttributes should not be added to the logger returned. |
bool | nullLogger | Optionally specifies that a do-nothing logger should be returned. This defaults to |
Returns
Type | Description |
---|---|
ILogger | The ILogger. |
CreateLogger(Type, LogAttributes, bool, bool)
Returns an ILogger using the fully qualified name from type
.
type as the logger's category name.
Declaration
public static ILogger CreateLogger(Type type, LogAttributes attributes = null, bool noAttributes = false, bool nullLogger = false)
Parameters
Type | Name | Description |
---|---|---|
Type | type | |
LogAttributes | attributes | Optionally specifies attributes to be included in every event logged. |
bool | noAttributes | Optionally indicates that the LogAttributes should not be added to the logger returned. |
bool | nullLogger | Optionally specifies that a do-nothing logger should be returned. This defaults to |
Returns
Type | Description |
---|---|
ILogger | The ILogger. |
CreateLogger<T>(LogAttributes, bool, bool)
Returns an ILogger using the fully qualified name of the T
type as the logger's category name.
Declaration
public static ILogger CreateLogger<T>(LogAttributes attributes = null, bool noAttributes = false, bool nullLogger = false)
Parameters
Type | Name | Description |
---|---|---|
LogAttributes | attributes | Optionally specifies attributes to be included in every event logged. |
bool | noAttributes | Optionally indicates that the LogAttributes should not be added to the logger returned. |
bool | nullLogger | Optionally specifies that a do-nothing logger should be returned. This defaults to |
Returns
Type | Description |
---|---|
ILogger | The ILogger. |
Type Parameters
Name | Description |
---|---|
T | Identifies the type whose fully-qualified name is to be used as the logger's category name. |
ParseLogLevel(string, LogLevel)
Parses a LogLevel from a string.
Declaration
public static LogLevel ParseLogLevel(string input, LogLevel @default = null)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input string. |
LogLevel | default | The default value to return when |
Returns
Type | Description |
---|---|
LogLevel | The parsed LogLevel. |