Exemplo n.º 1
0
        public StringBuilder PrettyPrintInfos(DateTime timeUtc)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("==================== ::INFOS:: ========================================");
            sb.AppendLine();
            sb.AppendFormat("Version: {0}", this.AssemblyVersion);
            sb.AppendLine();
            sb.AppendFormat("Client: {0}({1})", this.MachineName, this.IPAdresses);
            sb.AppendLine();
            sb.AppendFormat("User: {0}", this.UserName);
            sb.AppendLine();
            sb.AppendFormat("OS (Version|ServicePack|Platform): {0}|{1}|{2}", this.OsVersion, this.OsServicePack, this.OsPlatform);
            sb.AppendLine();
            sb.AppendFormat("Processorcount: {0}", this.ProcessorCount);
            sb.AppendLine();
            sb.AppendFormat("Framework: {0} || {1}", Environment.Version, this.HighestFrameworkVersion);
            sb.AppendLine();
            sb.AppendFormat("WPF Rendering Tier = {0}", this.RenderCapabilityTier);
            sb.AppendLine();
            sb.AppendFormat("System-Bit-Mode is: {0}", this.SystemBitInfo);
            sb.AppendLine();
            sb.AppendFormat("Uptime: {0}", TimeSpanUtil.UptimeString(timeUtc));
            sb.AppendLine();
            return(sb);
        }
Exemplo n.º 2
0
        public static void HandleUnhandledException(object exception, bool exitProgram)
        {
            if (Debugger.IsAttached)
            {
                // When debugging or running unit tests, let the unhandled exception surface.
                return;
            }

            // only allow one thread (UI)
            lock (lockErrorDialog)
            {
                try
                {
                    // check for special exitprogram conditions
                    if (!exitProgram)
                    {
                        exitProgram = ExceptionExtensions.IsFatalException((Exception)exception);
                    }

                    // prevent recursion on the message loop
                    if (!blockExceptionDialog)
                    {
                        blockExceptionDialog = true;

                        try
                        {
                            // only log once. Otherwise it is possible to fill the file system with exceptions (message pump + exception)
                            LogFatalException("UnhandledException", exception as Exception);
                        }
                        finally
                        {
                            if (!exitProgram)
                            {
                                blockExceptionDialog = false;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogFatalException("Unable to handle UnhandledException", ex);
                }
                finally
                {
                    if (exitProgram)
                    {
                        logger.Fatal($"Application exits due to UnhandledException, after uptime:{TimeSpanUtil.UptimeString(AppHelper.Instance.AppStartedUtcTime)}");

                        Environment.Exit(0);
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void OnApplicationExit(object sender, ExitEventArgs args)
 {
     // Not really fatal, but that way it is easy to find in the logs.
     logger.Info($"{this.ApplicationName} exits with exit-code {args.ApplicationExitCode} after uptime {TimeSpanUtil.UptimeString(this.AppStartedUtcTime)}");
     logger.Fatal("========================================:: {0} stopped", this.ApplicationName);
     LogManager.Shutdown();
 }
Exemplo n.º 4
0
        private void LogMemoryUsageAndInfos(object state)
        {
            var workingSetInMiB    = Environment.WorkingSet / 1024 / 1024;
            var gcTotalMemoryInMiB = GC.GetTotalMemory(true) / 1024 / 1024;
            var uptime             = DateTime.UtcNow - this.AppStartedUtcTime;

            logger.Info("{0} Memory-Usage (GC.GetTotalMemory(true)/Environment.WorkingSet): {1,4}/{2,4} MiB of instance {3} (uptime: {4} ({5:0.#####} minutes))", this.ApplicationName, workingSetInMiB, gcTotalMemoryInMiB, this.AppStartedUtcTime, TimeSpanUtil.ConvertMinutes2String(uptime.TotalMinutes), uptime.TotalMinutes);
        }
Exemplo n.º 5
0
 public string MemoryUsage(string applicationName, DateTime startedUtcTime)
 {
     return($"{applicationName} ({this.environmentHelper.ProcessId}) - Memory (Private Memory, WorkingSet, Peak WS): {this.environmentHelper.ProcessPrivateMemorySize}, {this.environmentHelper.ProcessWorkingSet}, {this.environmentHelper.ProcessPeakWorkingSet} - UpTime: {TimeSpanUtil.UptimeString(startedUtcTime)}");
 }