1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SuperSocket.Common;
- using SuperSocket.SocketBase.Logging;
- namespace SuperSocket.SocketBase
- {
-
-
-
- public static class LoggerExtension
- {
- private readonly static string m_SessionInfoTemplate = "Session: {0}/{1}";
-
-
-
-
-
-
-
- public static void Error(this ILog logger, ISessionBase session, string title, Exception e)
- {
- logger.Error(string.Format(m_SessionInfoTemplate, session.SessionID, session.RemoteEndPoint) + Environment.NewLine + title, e);
- }
-
-
-
-
-
-
- public static void Error(this ILog logger, ISessionBase session, string message)
- {
- logger.Error(string.Format(m_SessionInfoTemplate, session.SessionID, session.RemoteEndPoint) + Environment.NewLine + message);
- }
-
-
-
-
-
-
- public static void Info(this ILog logger, ISessionBase session, string message)
- {
- string info = string.Format(m_SessionInfoTemplate, session.SessionID, session.RemoteEndPoint) + Environment.NewLine + message;
- logger.Info(info);
- }
-
-
-
-
-
-
- public static void Debug(this ILog logger, ISessionBase session, string message)
- {
- if (!logger.IsDebugEnabled)
- return;
- logger.Debug(string.Format(m_SessionInfoTemplate, session.SessionID, session.RemoteEndPoint) + Environment.NewLine + message);
- }
- private const string m_PerfLogName = "Perf";
- private static ILog m_PerfLog;
-
-
-
-
-
- public static void LogPerf(this IAppServer appServer, string message)
- {
- if (m_PerfLog == null)
- {
- lock (m_PerfLogName)
- {
- if (m_PerfLog == null)
- {
- m_PerfLog = appServer.LogFactory.GetLog(m_PerfLogName);
- }
- }
- }
- if (m_PerfLog != null && m_PerfLog.IsInfoEnabled)
- m_PerfLog.Info(message);
- }
- }
- }
|