@@ -84,6 +84,13 @@ static class Global
8484 internal const string REGISTRY_5_BACKUP_SUBKEY = "Platform5Original" ; // Location that the original Platform 5 Profile will be copied to before migrating the 5.5 Profile back to the registry
8585 internal const string REGISTRY_55_BACKUP_SUBKEY = "Platform55Original" ; // Location that the original Platform 5.5 Profile will be copied to before removing Platform 5 and 5.5
8686 internal const string PLATFORM_VERSION_NAME = "PlatformVersion" ;
87+
88+ // TraceLogger constants
89+ internal const string USE_TRACELOGGER_MUTEX = "Use TraceLogger Mutex" ;
90+ internal const bool USE_TRACELOGGER_MUTEX_DEFAULT = false ;
91+ internal const string TRACELOGGER_DEBUG = "TraceLogger Debug" ; // This is not exposed in the Diagnostics UI, values must be changed by editing the registry.
92+ internal const bool TRACELOGGER_DEBUG_DEFAULT = false ;
93+
8794 // XML constants used by XMLAccess and RegistryAccess classes
8895 internal const string COLLECTION_DEFAULT_VALUE_NAME = "***** DefaultValueName *****" ; // Name identifier label
8996 internal const string COLLECTION_DEFAULT_UNSET_VALUE = "===== ***** UnsetValue ***** =====" ; // Value identifier label
@@ -570,77 +577,77 @@ internal static void LogEvent(string Caller, string Msg, EventLogEntryType Sever
570577 // It is wrong that an error in logging code should cause a client process to fail, so this code has been
571578 // made more robust and ultimately will swallow exceptions silently rather than throwing an unexpected exception back to the caller
572579
573- try
580+ try
581+ {
582+ if ( ! EventLog . SourceExists ( EVENT_SOURCE ) ) // Create the event log if it doesn't exist
574583 {
575- if ( ! EventLog . SourceExists ( EVENT_SOURCE ) ) // Create the event log if it doesn't exist
576- {
577- EventLog . CreateEventSource ( EVENT_SOURCE , EVENTLOG_NAME ) ;
578- ELog = new EventLog ( EVENTLOG_NAME , "." , EVENT_SOURCE ) ; // Create a pointer to the event log
579- ELog . ModifyOverflowPolicy ( OverflowAction . OverwriteAsNeeded , 0 ) ; // Force the policy to overwrite oldest
580- ELog . MaximumKilobytes = 1024L ; // Set the maximum log size to 1024kb, the Win 7 minimum size
581- ELog . Close ( ) ; // Force the log file to be created by closing the log
582- ELog . Dispose ( ) ;
583- ELog = null ;
584-
585- // MSDN documentation advises waiting before writing, first time to a newly created event log file but doesn't say how long...
586- // Waiting 3 seconds to allow the log to be created by the OS
587- System . Threading . Thread . Sleep ( 3000 ) ;
588-
589- // Try and create the initial log message
590- ELog = new EventLog ( EVENTLOG_NAME , "." , EVENT_SOURCE ) ; // Create a pointer to the event log
591- ELog . WriteEntry ( "Successfully created event log - Policy: " + ELog . OverflowAction . ToString ( ) + ", Size: " + ELog . MaximumKilobytes + "kb" , EventLogEntryType . Information , ( int ) EventLogErrors . EventLogCreated ) ;
592- ELog . Close ( ) ;
593- ELog . Dispose ( ) ;
594- }
595-
596- // Write the event to the log
584+ EventLog . CreateEventSource ( EVENT_SOURCE , EVENTLOG_NAME ) ;
597585 ELog = new EventLog ( EVENTLOG_NAME , "." , EVENT_SOURCE ) ; // Create a pointer to the event log
586+ ELog . ModifyOverflowPolicy ( OverflowAction . OverwriteAsNeeded , 0 ) ; // Force the policy to overwrite oldest
587+ ELog . MaximumKilobytes = 1024L ; // Set the maximum log size to 1024kb, the Win 7 minimum size
588+ ELog . Close ( ) ; // Force the log file to be created by closing the log
589+ ELog . Dispose ( ) ;
590+ ELog = null ;
598591
599- MsgTxt = Caller + " - " + Msg ; // Format the message to be logged
600- if ( Except is not null )
601- MsgTxt += Microsoft . VisualBasic . Constants . vbCrLf + Except ;
602- ELog . WriteEntry ( MsgTxt , Severity , ( int ) Id ) ; // Write the message to the error log
592+ // MSDN documentation advises waiting before writing, first time to a newly created event log file but doesn't say how long...
593+ // Waiting 3 seconds to allow the log to be created by the OS
594+ System . Threading . Thread . Sleep ( 3000 ) ;
603595
596+ // Try and create the initial log message
597+ ELog = new EventLog ( EVENTLOG_NAME , "." , EVENT_SOURCE ) ; // Create a pointer to the event log
598+ ELog . WriteEntry ( "Successfully created event log - Policy: " + ELog . OverflowAction . ToString ( ) + ", Size: " + ELog . MaximumKilobytes + "kb" , EventLogEntryType . Information , ( int ) EventLogErrors . EventLogCreated ) ;
604599 ELog . Close ( ) ;
605600 ELog . Dispose ( ) ;
606601 }
607- catch ( System . ComponentModel . Win32Exception ex ) // Special handling because these exceptions contain error codes we may want to know
602+
603+ // Write the event to the log
604+ ELog = new EventLog ( EVENTLOG_NAME , "." , EVENT_SOURCE ) ; // Create a pointer to the event log
605+
606+ MsgTxt = Caller + " - " + Msg ; // Format the message to be logged
607+ if ( Except is not null )
608+ MsgTxt += Microsoft . VisualBasic . Constants . vbCrLf + Except ;
609+ ELog . WriteEntry ( MsgTxt , Severity , ( int ) Id ) ; // Write the message to the error log
610+
611+ ELog . Close ( ) ;
612+ ELog . Dispose ( ) ;
613+ }
614+ catch ( System . ComponentModel . Win32Exception ex ) // Special handling because these exceptions contain error codes we may want to know
615+ {
616+ try
608617 {
609- try
610- {
611- string TodaysDateTime = Strings . Format ( DateTime . Now , "dd MMMM yyyy HH:mm:ss.fff" ) ;
612- string ErrorLog = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + @"\" + EVENTLOG_ERRORS ;
613- string MessageLog = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + @"\" + EVENTLOG_MESSAGES ;
618+ string TodaysDateTime = Strings . Format ( DateTime . Now , "dd MMMM yyyy HH:mm:ss.fff" ) ;
619+ string ErrorLog = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + @"\" + EVENTLOG_ERRORS ;
620+ string MessageLog = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + @"\" + EVENTLOG_MESSAGES ;
614621
615- // Write to backup event log message and error logs
616- File . AppendAllText ( ErrorLog , TodaysDateTime + " ErrorCode: 0x" + Conversion . Hex ( ex . ErrorCode ) + " NativeErrorCode: 0x" + Conversion . Hex ( ex . NativeErrorCode ) + " " + ex . ToString ( ) + Microsoft . VisualBasic . Constants . vbCrLf ) ;
617- File . AppendAllText ( MessageLog , TodaysDateTime + " " + Caller + " " + Msg + " " + Severity . ToString ( ) + " " + Id . ToString ( ) + " " + Except + Microsoft . VisualBasic . Constants . vbCrLf ) ;
618- }
619- catch ( Exception ) // Ignore exceptions here, the PC seems to be in a catastrophic failure!
620- {
622+ // Write to backup event log message and error logs
623+ File . AppendAllText ( ErrorLog , TodaysDateTime + " ErrorCode: 0x" + Conversion . Hex ( ex . ErrorCode ) + " NativeErrorCode: 0x" + Conversion . Hex ( ex . NativeErrorCode ) + " " + ex . ToString ( ) + Microsoft . VisualBasic . Constants . vbCrLf ) ;
624+ File . AppendAllText ( MessageLog , TodaysDateTime + " " + Caller + " " + Msg + " " + Severity . ToString ( ) + " " + Id . ToString ( ) + " " + Except + Microsoft . VisualBasic . Constants . vbCrLf ) ;
625+ }
626+ catch ( Exception ) // Ignore exceptions here, the PC seems to be in a catastrophic failure!
627+ {
621628
622- }
623629 }
624- catch ( Exception ex ) // Catch all other exceptions
630+ }
631+ catch ( Exception ex ) // Catch all other exceptions
632+ {
633+ // Something bad happened when writing to the event log so try and log it in a log file on the file system
634+ try
625635 {
626- // Something bad happened when writing to the event log so try and log it in a log file on the file system
627- try
628- {
629- string TodaysDateTime = Strings . Format ( DateTime . Now , "dd MMMM yyyy HH:mm:ss.fff" ) ;
630- string ErrorLog = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + @"\" + EVENTLOG_ERRORS ;
631- string MessageLog = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + @"\" + EVENTLOG_MESSAGES ;
636+ string TodaysDateTime = Strings . Format ( DateTime . Now , "dd MMMM yyyy HH:mm:ss.fff" ) ;
637+ string ErrorLog = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + @"\" + EVENTLOG_ERRORS ;
638+ string MessageLog = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + @"\" + EVENTLOG_MESSAGES ;
632639
633- // Write to backup event log message and error logs
634- File . AppendAllText ( ErrorLog , TodaysDateTime + " " + ex . ToString ( ) + Microsoft . VisualBasic . Constants . vbCrLf ) ;
635- File . AppendAllText ( MessageLog , TodaysDateTime + " " + Caller + " " + Msg + " " + Severity . ToString ( ) + " " + Id . ToString ( ) + " " + Except + Microsoft . VisualBasic . Constants . vbCrLf ) ;
636- }
637- catch ( Exception ) // Ignore exceptions here, the PC seems to be in a catastrophic failure!
638- {
640+ // Write to backup event log message and error logs
641+ File . AppendAllText ( ErrorLog , TodaysDateTime + " " + ex . ToString ( ) + Microsoft . VisualBasic . Constants . vbCrLf ) ;
642+ File . AppendAllText ( MessageLog , TodaysDateTime + " " + Caller + " " + Msg + " " + Severity . ToString ( ) + " " + Id . ToString ( ) + " " + Except + Microsoft . VisualBasic . Constants . vbCrLf ) ;
643+ }
644+ catch ( Exception ) // Ignore exceptions here, the PC seems to be in a catastrophic failure!
645+ {
639646
640- }
641647 }
642648 }
643-
649+ }
650+
644651 #endregion
645652
646653 #region Version Code
0 commit comments