Writing Synchronization Scripts in .NET
Writing .NET synchronization logic
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);
ErrorListener and WarningListener in ServerContext interface
SQL Anywhere Studio 9.0.2
Copyright © 1989–2004 Sybase, Inc. Portions copyright © 2001–2004 iAnywhere Solutions, Inc. All rights reserved.