Contents Index Printing information from .NET Debugging .NET synchronization logic

MobiLink Synchronization User's Guide
  Writing Synchronization Scripts in .NET
    Running .NET synchronization logic

Handling MobiLink server errors with .NET


When scanning the log is not sufficient, you can monitor your applications programmatically. For example, you can send messages of a certain type in an email.

You can write methods that are passed a class representing every error or warning message that is printed to the log. This may help you monitor and audit a MobiLink synchronization server.

The following code installs a Listener for all error messages and prints the information to a StreamWriter.

class TestLogListener {
    public TestLogListener( StreamWriter output_file  )
    {
        _output_file    = output_file;
    }
    public void errCallback( ServerContext sc, LogMessage lm )
    {
        string type;
        string user;
        if( lm.Type==LogMessage.MessageType.ERROR ) {
            type = "ERROR";
        } else if( lm.Type==LogMessage.MessageType.WARNING ) {
            type = "WARNING";
        } else {
            type = "INVALID TYPE!!";
        }
        if( lm.User == null ) {
            user = "null";
        } else {
            user = lm.User;
        }
        _output_file.WriteLine( "Caught msg type=" + type +
                                        " user=" + user +
                                        " text=" + lm.Text );
        _output_file.Flush();
    }
    StreamWriter    _output_file;
}
// Two lines that registers the TestLogListener Call this code
// from anywhere that has access to the ServerContext such as
// a class constructor or synchronization script.
// ServerContext serv_context;
TestLogListener etll = new TestLogListener(log_listener_file);
serv_context.ErrorListener += new LogCallback(etll.errCallback);
See also 

LogCallback delegate

ErrorListener and WarningListener in ServerContext interface

LogMessage class

MessageType enumeration


Contents Index Printing information from .NET Debugging .NET synchronization logic