Integrates UptoLog Satellite in client applications
This describes how
UptoLog Satellite
is integrated into a C# / .NET client application. Subsequently it is possible to use UptoLog Satellite
logging functionality.
Includes UptoLog Satellite
After UptoLog Satellite is
installed on the development client,
the UptoLog Satellite component is found under:
Windows Start menu --> UptoLog Satellite --> UptoLog Satellite library.
UptoLog Satellite is added to a project by creating a component folder in the project and copying
the two files UptoLog.Satellite.dll and UptoLog.Satellite.xml to the folder.
Afterwards a reference to UptoLog.Satellite.dll is created in the project(s),
which should use UptoLog Satellite.
Configuring UptoLog Satellite in app.config
It is configured what
UptoLog Log Server
that will receive logs and which types of logs that are active. The logging is only performed and sent
if the relevant type of log is active.
UptoLog Satellite configuration section is included in the configuration
element in the app.config file as follows:
<configSections>
<section name="UptoLog.Satellite.LogSettings"
type="UptoLog.Satellite.LogSettings,
UptoLog.Satellite, Version=3.0.1.7, Culture=neutral,
PublicKeyToken=37b0981e88140c28" />
</configSections>
The UptoLog Log Servers url and what types of logs that are active are configured in the
UptoLog.Satellite.LogSettings element in the app.config file as follows:
<UptoLog.Satellite.LogSettings>
<logServer url="http:// <!-- your server --> /UptoLog-LogServer/" />
<consumerType type="Client" />
<fatalError logActive="true" />
<error logActive="true" />
<warning logActive="true" />
<timeMeasure logActive="true" />
<trace logActive="true" />
</UptoLog.Satellite.LogSettings>
Logging unhandled exceptions
UptoLog Satellite should as a minimum log all unhandled exceptions, this is done by logging
all UI thread exceptions in the ThreadException event and all non-UI thread exceptions in the UnhandledException event.
Unhandled exceptions are logged as follows:
[STAThread]
static void Main()
{
// Add the event handler for handling UI thread exceptions to the event.
Application.ThreadException +=
new ThreadExceptionEventHandler(Application_ThreadException);
// Set the unhandled exception mode to force all Windows Forms errors
// to go through the handler.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
// Application code is put here.
}
UI thread exceptions are logged in the ThreadException event as follows:
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
// Logged as a fatal error.
Log.LogFatalError(e.Exception);
Application.Exit();
}
Non-UI thread exceptions are logged in the UnhandledException event as follows:
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.IsTerminating)
{
// Logged as a fatal error.
Log.LogFatalError(e.ExceptionObject as Exception);
}
else
{
// Logged as an error.
Log.LogError(e.ExceptionObject as Exception);
}
}
Activities in UptoLog
UptoLog Satellite holds an activity id which must be renewed every time a new
activity
is begun.
A client application normally begins a new activity every time the user clicks a button,
if this is the case, the guid must be renewed in UptoLog Satellite at every button click.
The activity id is renewed in UptoLog Satellite as follows:
Log.StartNewActivityId();
The activity id can subsequently be read in UptoLog Satellite as follows:
Guid someActivityId = Log.CurrentActivityId;
|