public void TestMethod1() { ShutdownHandler.Initialize(); Logger.Console.Verbose = VerboseLevel.Ultra; LogPublisher pub2; var pub1 = Logger.CreatePublisher(typeof(LoggerTest), MessageClass.Application); using (Logger.AppendStackMessages("Test2", "Adapter2")) pub2 = Logger.CreatePublisher(typeof(int), MessageClass.Application); Error1(pub2); using (Logger.SuppressFirstChanceExceptionLogMessages()) { Error1(pub2); } using (Logger.SuppressLogMessages()) { Error1(pub1); } using (Logger.SuppressLogMessages()) using (Logger.AppendStackMessages("Test1", "Adapter1")) using (Logger.OverrideSuppressLogMessages()) { Error1(pub2); } ShutdownHandler.InitiateSafeShutdown(); }
public void TestMethod1() { ShutdownHandler.Initialize(); Logger.Console.Verbose = VerboseLevel.Ultra; System.Console.WriteLine(LoadingAdjustedTimestamp.CurrentTime); Thread.Sleep(1000); System.Console.WriteLine(LoadingAdjustedTimestamp.CurrentTime); ShutdownHandler.InitiateSafeShutdown(); Thread.Sleep(1000); }
static void Main() { ShutdownHandler.Initialize(); try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new LogFileViewer()); } finally { ShutdownHandler.InitiateSafeShutdown(); } }
static Logger() { //Initializes the empty object of StackTraceDetails LogStackTrace.Initialize(); LogStackMessages.Initialize(); GrowStackDisposal(1); s_logger = new LoggerInternal(out s_logger); Console = new LogSubscriptionConsole(); FileWriter = new LogSubscriptionFileWriter(1000); AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Log = CreatePublisher(typeof(Logger), MessageClass.Component); Log.InitialStackTrace = LogStackTrace.Empty; EventFirstChanceException = Log.RegisterEvent(MessageLevel.NA, MessageFlags.SystemHealth, "First Chance App Domain Exception", 30, MessageRate.PerSecond(30), 1000); EventAppDomainException = Log.RegisterEvent(MessageLevel.Critical, MessageFlags.SystemHealth, "Unhandled App Domain Exception"); EventSwallowedException = Log.RegisterEvent(MessageLevel.Debug, MessageFlags.None, "Exception was Swallowed", 30, MessageRate.PerSecond(30), 1000); ShutdownHandler.Initialize(); }
private void ServiceHelper_ServiceStarting(object sender, EventArgs <string[]> e) { ShutdownHandler.Initialize(); // Define a run-time log m_runTimeLog = new RunTimeLog(); m_runTimeLog.FileName = "RunTimeLog.txt"; m_runTimeLog.ProcessException += ProcessExceptionHandler; m_runTimeLog.Initialize(); // Create a handler for unobserved task exceptions TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; // Make sure default service settings exist ConfigurationFile configFile = ConfigurationFile.Current; string servicePath = FilePath.GetAbsolutePath(""); string defaultLogPath = string.Format("{0}{1}Logs{1}", servicePath, Path.DirectorySeparatorChar); // Initialize algorithm processing framework - this will define default system settings try { AlgorithmHostingEnvironment.Initialize(); } catch (Exception ex) { HandleException(new InvalidOperationException($"Exception while creating framework for algorithm hosting environment: {ex.Message}", ex)); } CategorizedSettingsElementCollection systemSettings = configFile.Settings["systemSettings"]; // Makes sure exepected system settings are defined in the configuration file systemSettings.Add("LogPath", defaultLogPath, "Defines the path used to archive log files"); systemSettings.Add("MaxLogFiles", DefaultMaxLogFiles, "Defines the maximum number of log files to keep"); systemSettings.Add("AllowRemoteRestart", DefaultAllowRemoteRestart, "Controls ability to remotely restart the host service."); systemSettings.Add("AllowServiceMonitors", DefaultAllowServiceMonitors, "Controls ability to auto-load IServiceMonitor implementations."); systemSettings.Add("DefaultCulture", DefaultCulture, "Default culture to use for language, country/region and calendar formats."); systemSettings.Add("InputMapping", SystemSettings.InputMapping, "Mnput mapping used by algorithm for incoming data."); systemSettings.Add("OutputMapping", SystemSettings.OutputMapping, "Mapping used by algorithm for outgoing data."); systemSettings.Add("ConnectionString", SystemSettings.ConnectionString, "Connection string used by algorithm to connect to openECA data source."); systemSettings.Add("FramesPerSecond", SystemSettings.FramesPerSecond, "Data rate, in frames per second, expected by algorithm."); systemSettings.Add("LagTime", SystemSettings.LagTime, "Maximum past-time deviation tolerance, in seconds (can be sub-second), that the algorithm will tolerate."); systemSettings.Add("LeadTime", SystemSettings.LeadTime, "Maximum future-time deviation tolerance, in seconds (can be sub-second), that the algorithm will tolerate."); // Attempt to set default culture try { string defaultCulture = systemSettings["DefaultCulture"].ValueAs(DefaultCulture); CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(defaultCulture); // Defaults for date formatting, etc. CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture(defaultCulture); // Culture for resource strings, etc. } catch (Exception ex) { HandleException(new InvalidOperationException($"Failed to set default culture due to exception, defaulting to \"{CultureInfo.CurrentCulture.Name.ToNonNullNorEmptyString("Undetermined")}\": {ex.Message}", ex)); } // Retrieve application log path as defined in the config file string logPath = FilePath.GetAbsolutePath(systemSettings["LogPath"].Value); // Make sure log directory exists try { if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } } catch (Exception ex) { // Attempt to default back to common log file path if (!Directory.Exists(defaultLogPath)) { try { Directory.CreateDirectory(defaultLogPath); } catch { defaultLogPath = servicePath; } } HandleException(new InvalidOperationException($"Failed to create logging directory \"{logPath}\" due to exception, defaulting to \"{defaultLogPath}\": {ex.Message}", ex)); logPath = defaultLogPath; } int maxLogFiles = systemSettings["MaxLogFiles"].ValueAs(DefaultMaxLogFiles); try { Logger.FileWriter.SetPath(logPath); Logger.FileWriter.SetLoggingFileCount(maxLogFiles); } catch (Exception ex) { HandleException(new InvalidOperationException($"Failed to set logging path \"{logPath}\" or max file count \"{maxLogFiles}\" due to exception: {ex.Message}")); } try { Directory.SetCurrentDirectory(servicePath); } catch (Exception ex) { HandleException(new InvalidOperationException($"Failed to set current directory to execution path \"{servicePath}\" due to exception: {ex.Message}")); } // Initialize system settings as defined in configuration file m_allowRemoteRestart = systemSettings["AllowRemoteRestart"].ValueAs(DefaultAllowRemoteRestart); m_allowServiceMonitors = systemSettings["AllowServiceMonitors"].ValueAs(DefaultAllowServiceMonitors); SystemSettings.InputMapping = systemSettings["InputMapping"].ValueAs(SystemSettings.InputMapping); SystemSettings.OutputMapping = systemSettings["OutputMapping"].ValueAs(SystemSettings.OutputMapping); SystemSettings.ConnectionString = systemSettings["ConnectionString"].ValueAs(SystemSettings.ConnectionString); SystemSettings.FramesPerSecond = systemSettings["FramesPerSecond"].ValueAs(SystemSettings.FramesPerSecond); SystemSettings.LagTime = systemSettings["LagTime"].ValueAs(SystemSettings.LagTime); SystemSettings.LeadTime = systemSettings["LeadTime"].ValueAs(SystemSettings.LeadTime); }