// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; namespace Microsoft.Extensions.Logging { internal static class LoggingExtensions { private static Action _errorClosingTheSession; private static Action _accessingExpiredSession; private static Action _sessionStarted; private static Action _sessionLoaded; private static Action _sessionStored; private static Action _sessionCacheReadException; private static Action _errorUnprotectingCookie; static LoggingExtensions() { _errorClosingTheSession = LoggerMessage.Define( eventId: 1, logLevel: LogLevel.Error, formatString: "Error closing the session."); _accessingExpiredSession = LoggerMessage.Define( eventId: 2, logLevel: LogLevel.Warning, formatString: "Accessing expired session, Key:{sessionKey}"); _sessionStarted = LoggerMessage.Define( eventId: 3, logLevel: LogLevel.Information, formatString: "Session started; Key:{sessionKey}, Id:{sessionId}"); _sessionLoaded = LoggerMessage.Define( eventId: 4, logLevel: LogLevel.Debug, formatString: "Session loaded; Key:{sessionKey}, Id:{sessionId}, Count:{count}"); _sessionStored = LoggerMessage.Define( eventId: 5, logLevel: LogLevel.Debug, formatString: "Session stored; Key:{sessionKey}, Id:{sessionId}, Count:{count}"); _sessionCacheReadException = LoggerMessage.Define( eventId: 6, logLevel: LogLevel.Error, formatString: "Session cache read exception, Key:{sessionKey}"); _errorUnprotectingCookie = LoggerMessage.Define( eventId: 7, logLevel: LogLevel.Warning, formatString: "Error unprotecting the session cookie."); } public static void ErrorClosingTheSession(this ILogger logger, Exception exception) { _errorClosingTheSession(logger, exception); } public static void AccessingExpiredSession(this ILogger logger, string sessionKey) { _accessingExpiredSession(logger, sessionKey, null); } public static void SessionStarted(this ILogger logger, string sessionKey, string sessionId) { _sessionStarted(logger, sessionKey, sessionId, null); } public static void SessionLoaded(this ILogger logger, string sessionKey, string sessionId, int count) { _sessionLoaded(logger, sessionKey, sessionId, count, null); } public static void SessionStored(this ILogger logger, string sessionKey, string sessionId, int count) { _sessionStored(logger, sessionKey, sessionId, count, null); } public static void SessionCacheReadException(this ILogger logger, string sessionKey, Exception exception) { _sessionCacheReadException(logger, sessionKey, exception); } public static void ErrorUnprotectingSessionCookie(this ILogger logger, Exception exception) { _errorUnprotectingCookie(logger, exception); } } }