HSS Core Logging

The Logging library includes a .NET Service that writes entries to either the local machine event log or a database table.

When you install the HSS Core Framework, the Logging Service is installed for you and defaults to logging to the local machine event log.
If you want to log to a database, you can run the HSS Log Database Wizard which will create the HSSLOG database for you. It supports
installing into an existing database, or creating a new database. Also supports SqlExpress or Sql Server.

Once configured, you add a reference to the HSS.Core.dll and then call...

using HSS.Logging;

// Write a simple message
Log.WriteEntry("message", EventLogEntryType.Information);

// or from within a try catch

        // some task that throws an execption
catch (Exception ex)
There are several overrides and additional helper methods that make it super convenient to write different types of messages to the log. Including
support for adding attachments to the entry when logging to the database.

Additionally, from your application initialization, you can designate the default application name, user name and entry formatter.

// Configure Logging
Log.DefaultApplicationName = "Your App";
Log.DefaultUserName = "System";
Log.Formatter = new CustomFormatter();

/// <summary>
/// Custom Log Entry Formatter
/// </summary>
public class CustomFormatter
    // Format exception entries
    public void FormatException(Exception ex, HSS.Logging.LogEntry entry, HSS.Logging.ILog log)

    // Format non exception entries
    public void Format(HSS.Logging.LogEntry entry, HSS.Logging.ILog log)

Last edited Aug 8, 2010 at 4:05 PM by hyspdrt, version 4


No comments yet.