SocketSession.Net.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Sockets;
  6. using SuperSocket.SocketBase;
  7. namespace SuperSocket.SocketEngine
  8. {
  9. abstract partial class SocketSession
  10. {
  11. private const string m_GeneralErrorMessage = "Unexpected error";
  12. private const string m_GeneralSocketErrorMessage = "Unexpected socket error: {0}";
  13. /// <summary>
  14. /// Logs the error, skip the ignored exception
  15. /// </summary>
  16. /// <param name="exception">The exception.</param>
  17. protected void LogError(Exception exception)
  18. {
  19. int socketErrorCode;
  20. //This exception is ignored, needn't log it
  21. if (IsIgnorableException(exception, out socketErrorCode))
  22. return;
  23. var message = socketErrorCode > 0 ? string.Format(m_GeneralSocketErrorMessage, socketErrorCode) : m_GeneralErrorMessage;
  24. AppSession.Logger.Error(this, message, exception);
  25. }
  26. /// <summary>
  27. /// Logs the error, skip the ignored exception
  28. /// </summary>
  29. /// <param name="message">The message.</param>
  30. /// <param name="exception">The exception.</param>
  31. protected void LogError(string message, Exception exception)
  32. {
  33. int socketErrorCode;
  34. //This exception is ignored, needn't log it
  35. if (IsIgnorableException(exception, out socketErrorCode))
  36. return;
  37. AppSession.Logger.Error(this, message, exception);
  38. }
  39. /// <summary>
  40. /// Logs the socket error, skip the ignored error
  41. /// </summary>
  42. /// <param name="socketErrorCode">The socket error code.</param>
  43. protected void LogError(int socketErrorCode)
  44. {
  45. if (!Config.LogAllSocketException)
  46. {
  47. //This error is ignored, needn't log it
  48. if (IsIgnorableSocketError(socketErrorCode))
  49. return;
  50. }
  51. AppSession.Logger.Error(this, string.Format(m_GeneralSocketErrorMessage, socketErrorCode), new SocketException(socketErrorCode));
  52. }
  53. }
  54. }