LoggerExtensions Class
HAKOM.Logging.HakomDatabaseLog.Net.Api.Extensions
Section titled “HAKOM.Logging.HakomDatabaseLog.Net.Api.Extensions”Adds extension methods to Microsoft.Extensions.Logging.ILogger for database logging specific calls.
public static class LoggerExtensionsInheritance System.Object 🡒 LoggerExtensions
Remarks
Section titled “Remarks”This class provides two key extensions: BeginSession(this ILogger) for managing logging sessions, and LogProgress(this ILogger, string, object[]) for writing progress-level entries.
Methods
Section titled “Methods”LoggerExtensions.BeginSession(this ILogger) Method
Section titled “LoggerExtensions.BeginSession(this ILogger) Method”Starts a new logging Session by calling Microsoft.Extensions.Logging.ILogger.BeginScope<>(@@0) with a freshly created Session as the state.
public static System.IDisposable? BeginSession(this Microsoft.Extensions.Logging.ILogger logger);Parameters
Section titled “Parameters”logger Microsoft.Extensions.Logging.ILogger
The Microsoft.Extensions.Logging.ILogger to start a session for.
Returns
Section titled “Returns”System.IDisposable
An System.IDisposable that ends the session when disposed, or null if the logger does not support scopes.
Exceptions
Section titled “Exceptions”System.ArgumentNullException
Thrown if logger is null.
Remarks
Section titled “Remarks”When the logger is a HAKOM database logger, the session is created through the registered ISessionFactory and tracked by the scope provider. When the returned System.IDisposable is disposed, a “Session closed” log entry is written automatically and the session is marked inactive.
When the logger is not a HAKOM database logger (e.g. a console or file logger), a Session with a random System.Guid is created and passed as a regular scope state. No database-specific behavior occurs in this case.
using (logger.BeginSession()){ logger.LogInformation("Import started"); // ... do work ... logger.LogInformation("Import completed");}LoggerExtensions.LogProgress(this ILogger, string, object[]) Method
Section titled “LoggerExtensions.LogProgress(this ILogger, string, object[]) Method”Writes a progress-level log entry by calling Microsoft.Extensions.Logging.LoggerExtensions.Log(Microsoft.Extensions.Logging.ILogger,Microsoft.Extensions.Logging.LogLevel,System.String,System.Object[]) with Microsoft.Extensions.Logging.LogLevel.None.
public static void LogProgress(this Microsoft.Extensions.Logging.ILogger logger, string message, params object[]? args);Parameters
Section titled “Parameters”logger Microsoft.Extensions.Logging.ILogger
The Microsoft.Extensions.Logging.ILogger to write the progress entry to.
message System.String
The message to log. Supports positional format placeholders.
args System.Object[]
Optional array of parameters to substitute into the message template.
Exceptions
Section titled “Exceptions”System.ArgumentNullException
Thrown if logger is null.
Remarks
Section titled “Remarks”Progress entries map to the legacy HAKOM LogType.Progress (value 3) in the database.
They are intended for tracking the progress of long-running operations and are distinct
from informational, warning, or error messages.
The message parameter supports the standard .NET logging message
template syntax with positional placeholders (e.g. "Processing item {0} of {1}").