The LoggingDCF33Style example demonstrates how to programatically configure an NLog adapter to use a DCF33 style header
with an NLog ColoredConsoleTarget. Additional DCF Logger configuration and method calls are also demonstrated.
Classes
Class | Description | |
---|---|---|
DCF33StyleNLogAdapter |
Adapter class to support using NLog as the back end log facility, and configured to use DCF33 style headers.
| |
Program |
Example to configure NLog to emit log message headers using the DCF33 log message header format.
|
Remarks
Supported OS Platforms:
- Windows - .Net Framework 4.7.2 64-bit and 32-bit
- Windows - .Net Core 2.1 64-bit and 32-bit
- Linux - .Net Core 2.1 64-bit
Examples
LoggingDCF33Style Sample Code
public class Program { private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); /// <summary> /// Main entry point for LoggingDCF33Style. /// </summary> [STAThread] public static void Main() { try { // This adapter outputs through the ColoredConsoleTarget LogManager.LogAdapter = new DCF33StyleNLogAdapter(); // Create our default session settings. DicomSessionSettings ss = new DicomSessionSettings() { LevelFlags = LF.Default, // Fatal, Error, Warn, Info, Debug but not Verbose DebugFlags = DF.None // The default DebugFlags is None }; // Log with a DicomSessionSettings which is the typical way library classes invoke the logger // If an I/O base class is passed a null session settings, one will be default constructed Logger.Fatal(ss, "Fatal with DicomSessionSettings."); Logger.Error(ss, "Error with DicomSessionSettings."); Logger.Warn(ss, "Warn with DicomSessionSettings."); Logger.Info(ss, "Info with DicomSessionSettings."); Logger.Debug(DF.All, ss, "Debug DF.All with DicomSessionSettings."); Logger.Debug(DF.FilterSummary, ss, "Debug DF.FilterSummary with DicomSessionSettings NOT DISPLAYED."); Logger.Verbose(ss, "Verbose with DicomSessionSettings NOT DISPLAYED."); // Set the Framework DefaultSessionSettings to log all levels and all debug message types - egads! Framework.DefaultSessionSettings.LevelFlags = LF.All; Framework.DefaultSessionSettings.DebugFlags = DF.All; // Thread log settings - the using disposes the thread local log settings when the block is exited using (var tLogSettings = LogSettings.SetThreadLogSettings(new DicomSessionSettings { LevelFlags = LF.Fatal | LF.Error })) { Logger.Fatal("Fatal with Thread LogSettings."); Logger.Error("Error with Thread LogSettings."); Logger.Warn("Warn with Thread LogSettings NOT DISPLAYED."); Logger.Info("Info with Thread LogSettings NOT DISPLAYED."); Logger.Debug(DF.All, "Debug DF.All with Thread LogSettings NOT DISPLAYED."); Logger.Debug(DF.FilterSummary, "Debug DF.FilterSummary with Thread LogSettings NOT DISPLAYED."); Logger.Verbose("Verbose with Thread LogSettings NOT DISPLAYED."); } // These calls use the DefaultSessionSettings which was configured above to be copious Logger.Fatal("Fatal with DefaultSessionSettings."); Logger.Error("Error with DefaultSessionSettings."); Logger.Warn("Warn with DefaultSessionSettings."); Logger.Info("Info with DefaultSessionSettings."); Logger.Debug(DF.All, "Debug DF.All with DefaultSessionSettings."); Logger.Debug(DF.FilterSummary, "Debug DF.FilterSummary with DefaultSessionSettings."); Logger.Verbose("Verbose with DefaultSessionSettings."); } catch (Exception e) { Console.WriteLine("Error during execution: {0}", e); Environment.ExitCode = 1; } if (System.Diagnostics.Debugger.IsAttached) { Console.Write("Press any key to continue . . . "); Console.ReadKey(); } } }