LaurelBridge.DCF.Examples.BasicFileLogging Namespace
LAUREL BRIDGE

LaurelBridge.DCF.Examples.BasicFileLogging Namespace

DICOM Connectivity Framework V3.4
The BasicFileLogging example demonstrates various logging capabilities in DCF.
Classes

  ClassDescription
Public classProgram
Configure simple logging to a file, demonstrate various logging levels and debug logging interfaces.

The debug logging facilities are very useful in providing message dumps of DICOM dimse messages and datasets. The DicomSessionSettings also implements the ILogSettings interface which is used to set logging properties and enable DICOM inputs and outputs to tailor log output on a per-session basis.

This executable will start up a notepad process to view the log output before exiting.

Examples

BasicFileLogging Sample Code
public class Program
{
    private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();

    /// <summary>
    /// Main program for BasicFileLogging example.
    /// </summary>
    [STAThread]
    public static void Main()
    {
        string logFilePath = "BasicFileLogging.txt";

        // Cleanup any existing log files
        if (File.Exists(logFilePath))
            File.Delete(logFilePath);
        try
        {
            // Set the log adapter to use the basic file log adapter
            LogManager.LogAdapter = new FileLogAdapter(logFilePath);

            // Create the session settings object to use for this session and enable debug logging
            DicomSessionSettings sessionSettings = new DicomSessionSettings();
            sessionSettings.IsDebugEnabled = true;

            // Various log levels using the recently created session settings object
            Logger.Verbose(sessionSettings, "Example verbose message that should NOT be logged.");
            Logger.DebugFormat(DF.All, sessionSettings, "Example debug log message with debug flags({0})", DF.All);
            Logger.Info(sessionSettings, "Example info log message.");

            // Logging using the default session settings object
            // Note the session id (in the log message header) is different for this log message than 
            // the id for messages using the session settings object created above.
            Logger.Info("Example info log message using the default session.");

            // Logging before and after setting the debug flags.
            // Note that the debug message with the configuration debug flag was not logged because 
            // the session settings debug flags did not have User1 set.
            Logger.Debug(DF.User1, "Debug log message will NOT be logged because of debug flag not matching the session.");
            sessionSettings.DebugFlags = DF.User1;
            Logger.DebugFormat(DF.User1, sessionSettings, "Debug flag will now be logged after updating the session flags({0})", sessionSettings.DebugFlags);

            Console.WriteLine("Log output written to file: {0}", logFilePath);
            Process.Start("notepad.exe", logFilePath);
        }
        catch (Exception e)
        {
            Console.WriteLine("Error setting up file based logger: {0}", e);
        }

        if (Debugger.IsAttached)
        {
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey();
        }
    }
}