using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using SuperSocket.SocketBase;
namespace SuperSocket.SocketEngine
{
abstract partial class SocketSession
{
private const string m_GeneralErrorMessage = "Unexpected error";
private const string m_GeneralSocketErrorMessage = "Unexpected socket error: {0}";
private const string m_CallerInformation = "Caller: {0}, file path: {1}, line number: {2}";
///
/// Logs the error, skip the ignored exception
///
/// The exception.
/// The caller.
/// The caller file path.
/// The caller line number.
protected void LogError(Exception exception, [CallerMemberName] string caller = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
{
int socketErrorCode;
//This exception is ignored, needn't log it
if (IsIgnorableException(exception, out socketErrorCode))
return;
var message = socketErrorCode > 0 ? string.Format(m_GeneralSocketErrorMessage, socketErrorCode) : m_GeneralErrorMessage;
AppSession.Logger.Error(this
, message + Environment.NewLine + string.Format(m_CallerInformation, caller, callerFilePath, callerLineNumber)
, exception);
}
///
/// Logs the error, skip the ignored exception
///
/// The message.
/// The exception.
/// The caller.
/// The caller file path.
/// The caller line number.
protected void LogError(string message, Exception exception, [CallerMemberName] string caller = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
{
int socketErrorCode;
//This exception is ignored, needn't log it
if (IsIgnorableException(exception, out socketErrorCode))
return;
AppSession.Logger.Error(this
, message + Environment.NewLine + string.Format(m_CallerInformation, caller, callerFilePath, callerLineNumber)
, exception);
}
///
/// Logs the socket error, skip the ignored error
///
/// The socket error code.
/// The caller.
/// The caller file path.
/// The caller line number.
protected void LogError(int socketErrorCode, [CallerMemberName] string caller = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
{
if (!Config.LogAllSocketException)
{
//This error is ignored, needn't log it
if (IsIgnorableSocketError(socketErrorCode))
return;
}
AppSession.Logger.Error(this
, string.Format(m_GeneralSocketErrorMessage, socketErrorCode) + Environment.NewLine + string.Format(m_CallerInformation, caller, callerFilePath, callerLineNumber)
, new SocketException(socketErrorCode));
}
}
}