using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Extensions.Logging; using SuperSocket.Common; using SuperSocket.SocketBase.Logging; namespace SuperSocket.SocketBase { /// /// Logger extension class /// public static class LoggerExtension { private readonly static string m_SessionInfoTemplate = "Session: {0}/{1}"; /// /// Logs the error /// /// The logger. /// The session. /// The title. /// The e. public static void LogError(this ILogger logger, ISessionBase session, Exception e) { logger.LogError(string.Format(m_SessionInfoTemplate, session.SessionID, session.RemoteEndPoint) + Environment.NewLine, e); } /// /// Logs the error /// /// The logger. /// The session. /// The title. /// The e. public static void LogError(this ILogger logger, ISessionBase session, string title, Exception e) { logger.LogError(string.Format(m_SessionInfoTemplate, session.SessionID, session.RemoteEndPoint) + Environment.NewLine + title, e); } /// /// Logs the error /// /// The logger. /// The session. /// The message. public static void LogError(this ILogger logger, ISessionBase session, string message) { logger.LogError(string.Format(m_SessionInfoTemplate, session.SessionID, session.RemoteEndPoint) + Environment.NewLine + message); } /// /// Logs the information /// /// The logger. /// The session. /// The message. public static void LogInfo(this ILogger logger, ISessionBase session, string message) { string info = string.Format(m_SessionInfoTemplate, session.SessionID, session.RemoteEndPoint) + Environment.NewLine + message; logger.LogInformation(info); } /// /// Logs the debug message /// /// The logger. /// The session. /// The message. public static void LogDebug(this ILogger logger, ISessionBase session, string message) { logger.LogDebug(string.Format(m_SessionInfoTemplate, session.SessionID, session.RemoteEndPoint) + Environment.NewLine + message); } private const string m_PerfLogName = "Perf"; private static ILogger m_PerfLog; /// /// Logs the performance message /// /// The app server. /// The message. public static void LogPerf(this IAppServer appServer, string message) { if (m_PerfLog == null) { lock (m_PerfLogName) { if (m_PerfLog == null) { m_PerfLog = appServer.LogFactory.CreateLogger(m_PerfLogName); } } } if (m_PerfLog != null) m_PerfLog.LogInformation(message); } } }