예제 #1
0
        public static void RunTest()
        {
            // Uncomment the MSMQLog line out if you have MSMQ setup with a private queue called NOC
            // MemFileLogTest();

            FileLog backupFileLog = new FileLog("TestBackupLog", "", enumEventPriority.All);

            LoggingMgr lm = new LoggingMgr(
                new List <ILoggingTarget>()
            {
                new WindowsEventLog("Application", "LoggingTest", backupFileLog, enumEventPriority.Critical),
                new FileLog("ApplicationLogFile", Environment.CurrentDirectory, enumEventPriority.All),
                //new FastFileLog( "FastLogFile_" + Process.GetCurrentProcess().Id.ToString(),
                new MemoryFileLog("LoggingTestLog", "LogFile",
                                  Environment.CurrentDirectory, 10000, enumEventPriority.All)
                //new MSMQLog( "MSMQLog", ".\\Private$\\NOC", backupFileLog, enumEventPriority.Critical,
                //        enumEventPriority.Normal)
            }
                , backupFileLog, enumTraceLevel.All);

            //This should log in the Windows Event Log and the file log at c:\applicationLogFile_*.txt
            lm.WriteToLog("Test Log 1: Critical", System.Diagnostics.EventLogEntryType.Information,
                          enumEventPriority.Critical);

            //This should log only in the file log at c:\applicationLogFile_*.txt
            lm.WriteToLog("Test Log 2: Normal", System.Diagnostics.EventLogEntryType.Information,
                          enumEventPriority.Normal);

            // Should only go in FileLog at c:\applicationLogFile_*.txt
            lm.Trace("Trace Token");

            // You can also construct the LoggingMgr with the following constructor. This will give you a default of
            //  windows event logging with a backup text file
            LoggingMgr lmDefault = new LoggingMgr("Application", "LoggingTest", "c:", enumTraceLevel.All);

            lmDefault.WriteToLog("Test Default Log", EventLogEntryType.Information, enumEventPriority.Normal);
        }
예제 #2
0
 private static void HandleException(Exception e)
 {
     try
     {
         LoggingMgr loggingMgr = new LoggingMgr(AppConfigMgr.GetValue(Configuration.Constants.LoggingKey).ToString());
         loggingMgr.WriteToLog(e, enumEventPriority.Critical);
     }
     finally
     {
         string errorFileName = "DbSetupMgr.Exception.txt";
         string msg           = "Will attempt to write exception details to file: " + errorFileName
                                + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace + Environment.NewLine;
         MessageBox.Show(msg, "Fatal Error - Look for file: " + errorFileName);
         FileManagement.FileMgr.WriteTextToFile(errorFileName, msg, false, true);
     }
 }