SuperSocket内置了日志功能,你只需通过下面两个步骤来启用它:

1) 包含SuperSocket提供的配置文件log4net.config到你的启动程序的/Config目录

2) 如果你用自定义容器运行SuperSocket,请确认您添加了LogUtil.Setup(); 这段代码到程序入口位置,用于启用SuperSocket日志功能

 

SuperSocket的AppServer和AppSession都有Logger属性,你可以直接使用他们来记录日志。

SuperSocket的日志是以文件的形式存放在运行目录的Logs子目录里面,Log相关的配置请参考文档

http://www.cnblogs.com/jzywh/archive/2011/04/20/2022946.html

某项目AppServer类中有如下代码:

if (string.IsNullOrEmpty(m_PolicyFile))
{
    Logger.LogError("Configuration option policyFile is required!");
    return false;
}

以上代码会将错误信息"Configuration option policyFile is required!"记录到err.log文件里面

你也可以用同样的方式通过Session的Logger来记录日志信息:

public class RemoteProcessSession : AppSession<RemoteProcessSession>
{
    public override void HandleUnknownCommand(StringCommandInfo cmdInfo)
    {
        Logger.LogInfo(string.Format("Found one unknown command {0}!", cmdInfo.Key));
    }
}

如果你也想同时记录下该Session的标识信息, 你可以将Session作为Log方法的第一个参数,如同下面代码:

public class RemoteProcessSession : AppSession<RemoteProcessSession>
{
    public override void HandleUnknownCommand(StringCommandInfo cmdInfo)
    {
        Logger.LogInfo(this, string.Format("Found one unknown command {0}!", cmdInfo.Key));
    }
}

相关文章:

  • 2021-10-15
  • 2021-07-06
  • 2021-08-31
  • 2021-09-26
  • 2021-08-10
  • 2021-07-18
  • 2021-09-27
  • 2022-12-23
猜你喜欢
  • 2021-12-20
  • 2021-07-23
  • 2021-08-23
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
  • 2022-02-16
相关资源
相似解决方案