Class LogUtil
- Namespace
- Invex.Extensions.Logging.Utils
- Assembly
- Invex.Extensions.Logging.Utils.dll
Creates standalone loggers for host lifecycle messages and writes application startup information.
public static class LogUtil
- Inheritance
-
objectLogUtil
Remarks
The factories created here are independent of any application's host and dependency injection container. Register logging providers in the configuration callback and dispose the returned logger or factory when it is no longer needed.
Methods
CreateHostLogger(Action<ILoggingBuilder>?)
Creates a logger with the category Host and an owned, standalone logger factory.
public static HostLogger CreateHostLogger(Action<ILoggingBuilder>? configure = null)
Parameters
configureAction<ILoggingBuilder>An optional callback that registers providers and configures logging after the default
Microsoftcategory filter has been added. No providers are registered automatically.
Returns
- HostLogger
A logger that disposes its factory and the factory-owned providers when disposed.
Remarks
Use this logger before building a host or after stopping one. It does not inherit the host's providers,
configuration, or services. The default category filter permits Microsoft entries at
Microsoft.Extensions.Logging.LogLevel.Warning and above; the callback can add further filtering rules.
CreateHostLoggerFactory(Action<ILoggingBuilder>?)
Creates a standalone logger factory with a Microsoft category filter at
Microsoft.Extensions.Logging.LogLevel.Warning.
public static ILoggerFactory CreateHostLoggerFactory(Action<ILoggingBuilder>? configure = null)
Parameters
configureAction<ILoggingBuilder>An optional callback that registers providers and configures logging after the default filter is added. No providers are registered automatically.
Returns
- ILoggerFactory
A standalone factory that the caller must dispose when it is no longer needed.
Remarks
The factory does not automatically load host configuration or use a host's services. Use the callback to register providers, bind configuration if required, and add filtering rules. Disposing the factory disposes providers that it owns, including providers created by its dependency injection container.
LogStartupInfo(ILogger, string?, string?, string?, string?)
Writes an information-level startup message with explicit application, version, machine, and environment values, if that level is enabled.
public static void LogStartupInfo(ILogger logger, string? applicationName, string? version, string? machineName, string? environment)
Parameters
loggerILoggerThe logger that receives the startup message.
applicationNamestringThe application name, or null/empty to display
Application.versionstringThe version, or null/empty to omit it. Leading
vandVcharacters are removed before a singlevprefix is added.machineNamestringThe machine name, or null/empty to omit the
onclause.environmentstringThe environment name, or null/empty to omit the
in ... configurationclause.
Remarks
The message order is Started {application} v{version} on {machine} in {environment} configuration.
Optional clauses include their own leading space, and whitespace-only values are retained. The template is
Started{AppName}{Version}{MachineName}{Environment}: MachineName receives the machine clause,
and Environment receives the environment clause. Structured values include these formatted clauses
rather than the raw inputs. Logging failures from the supplied logger are not caught.
LogStartupInfo<T>(ILogger, IHostEnvironment?)
Writes an information-level startup message using the assembly containing T.
public static void LogStartupInfo<T>(ILogger logger, IHostEnvironment? environment = null)
Parameters
loggerILoggerThe logger that receives the startup message.
environmentIHostEnvironmentAn optional host environment whose Microsoft.Extensions.Hosting.IHostEnvironment.EnvironmentName is included in the message. Its Microsoft.Extensions.Hosting.IHostEnvironment.ApplicationName does not supply the application name.
Type Parameters
TA type whose assembly supplies the application name and assembly version.
Remarks
Uses the assembly's simple name and AssemblyName.Version, rather than its file or informational
version, and System.Environment.MachineName. The explicit-value overload determines formatting
and skips the message when Microsoft.Extensions.Logging.LogLevel.Information is disabled. Calling this method does
not start a host or verify that it started successfully.