Logger in SuperSocket

There are two steps to do if you want to enable built-in logging feature of SuperSocket:

1) Included file "log4net.config" provided by SuperSocket into your start-up project's sub directory "Config" and set this file's build action to be Content and Copy if newer.

2) If you run SuperSocket in your customized start up project, please insert the code line "LogUtil.Setup()" before SuperSocket initialization.

The AppServer and AppSession of SuperSocket have Logger properties, you can use them for logging.
SuperSocket log files are stored in the the subdirectory "Logs" of the current running directory.
Log-related configuration, refer to documentation
http://supersocket.codeplex.com/wikipage?title=Basic%20configuration&referringTitle=Documentation

The AppServer class of one project has below code:
if (string.IsNullOrEmpty(m_PolicyFile))
{
    Logger.LogError("Configuration option policyFile is required!");
    return false;
}

The above code will log the error message "Configuration option policyFile is required!" into logging file err.log.

You can also use the same way through the Logger property of session to log information:
public class RemoteProcessSession : AppSession<RemoteProcessSession>
{
    public override void HandleUnknownCommand(StringCommandInfo cmdInfo)
    {
        Logger.LogInfo(string.Format("Found one unknown command {0}!", cmdInfo.Key));
    }
}

If you would like to also record the identification information of the Session, you can pass in the Session as the first argument into Log method, as in the following code:
public class RemoteProcessSession : AppSession<RemoteProcessSession>
{
    public override void HandleUnknownCommand(StringCommandInfo cmdInfo)
    {
        Logger.LogInfo(this, string.Format("Found one unknown command {0}!", cmdInfo.Key));
    }
}

Last edited Apr 5, 2012 at 2:30 AM by kerryjiang, version 9

Comments

Rushino Oct 20, 2012 at 3:03 PM 
Where is located the LogUtil class ?