public LogEntry(DateTime time, string origin, SeverityOption severity, string message) { Time = time; Origin = origin ?? throw new ArgumentNullException(nameof(origin)); Severity = severity; Message = message ?? throw new ArgumentNullException(nameof(message)); }
/// <summary> /// Constructor /// </summary> /// <param name="errorMessage">The error that has occured.</param> /// <param name="severity">What is the severity of this exception?</param> public TechnolutionException(string errorMessage, SeverityOption severity = SeverityOption.Undefined) : base(errorMessage) { try { Severity = severity; } catch (Exception e) { TechnolutionExceptionStack ex = new TechnolutionExceptionStack(e); ex.LogParameterValue(errorMessage, "errorMessage"); ex.LogParameterValue(severity, "severity"); throw ex.GetStackToThrow(); } }
private void btnOk_Click(object sender, RoutedEventArgs e) { var settingsViewModel = DataContext as SettingsViewModel; Settings.Instance.AlwaysOnTop = settingsViewModel.AlwaysOnTop; Settings.Instance.NamedPipeAddress = settingsViewModel.NamedPipeAddress; SeverityOption severity = SeverityOption.Warning; if (Enum.TryParse(settingsViewModel.MinimalSeverityToShowInLog, out severity)) { Settings.Instance.MinimalSeverityToShowInLog = severity; } Settings.Instance.SaveSettings(); Close(); }
/// <summary> /// Constuctor for an exception stack to be logged. /// </summary> /// <param name="exception">The exception that was caught.</param> /// <param name="severity">The severity of this exception.</param> public TechnolutionExceptionStack(Exception exception, SeverityOption severity = SeverityOption.Undefined) : base(exception.Message) { try { if (exception is TechnolutionExceptionStack) { InvertedStack = ((TechnolutionExceptionStack)exception); OriginalException = ((TechnolutionExceptionStack)exception).OriginalException; } else OriginalException = exception; Parameters = new Dictionary<string, string>(); Configure(exception, severity); } catch (Exception e) { TechnolutionExceptionStack te = new TechnolutionExceptionStack(e); te.LogParameterValue(exception, "exception"); throw te.GetStackToThrow(); } }
/// <summary> /// Configures the exception stack /// </summary> /// <param name="innerException">The inner exception that was caught.</param> /// <param name="severity">The severity of the exception.</param> private void Configure(Exception innerException, SeverityOption severity) { try { Severity = severity; StackFrame sf = null; MethodBase method = null; StackTrace st = new StackTrace(innerException, true); for (int i = 0; i < st.FrameCount; i++) { sf = st.GetFrame(i); method = sf.GetMethod(); if ((method.DeclaringType != typeof(TechnolutionExceptionStack)) && (method.DeclaringType != typeof(TechnolutionException))) { break; } } if (sf == null) { LineNumber = 0; CodeClassName = "Unknown, could not resolve stack trace"; MethodName = "Unknown, could not resolve stack trace"; AssemblyName = "Unknown, could not resolve stack trace"; return; } LineNumber = sf.GetFileLineNumber(); CodeClassName = method.DeclaringType.FullName; MethodName = method.Name; AssemblyName assemblyName = method.Module.Assembly.GetName(); AssemblyName = assemblyName.Name; AssemblyVersion = assemblyName.Version.ToString(); if (!(innerException is TechnolutionException)) { if (severity == SeverityOption.Undefined) { if (innerException is NotImplementedException) { Severity = SeverityOption.NotImplemented; } else if ((innerException is InvalidProgramException) || (innerException is InvalidOperationException) || (innerException is InvalidCastException) || (innerException is NullReferenceException) || (innerException is NotSupportedException)) { Severity = SeverityOption.Critical; } } } } catch (Exception e) { TechnolutionExceptionStack ex = new TechnolutionExceptionStack(e); ex.LogParameterValue(innerException, "innerException"); ex.LogParameterValue(severity, "severity"); throw ex.GetStackToThrow(); } }