bovender framework
C# framework that implements MVVM and more
CentralHandler.cs
1 /* CentralHandler.cs
2  * part of Daniel's XL Toolbox NG
3  *
4  * Copyright 2014-2018 Daniel Kraus
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 using System;
19 
20 namespace Bovender.ExceptionHandler
21 {
37  public static class CentralHandler
38  {
39  #region Events
40 
41  public static event EventHandler<ManageExceptionEventArgs> ManageExceptionCallback;
42 
43  #endregion
44 
45  #region Static methods
46 
56  public static bool Manage(object origin, Exception e)
57  {
59  if (ManageExceptionCallback != null)
60  {
61  ManageExceptionCallback(origin, args);
62  }
63  return args.IsHandled;
64  }
65 
69  public static void AppDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
70  {
71  string dump =
72  "AppDomain_UnhandledException dump" + Environment.NewLine +
73  DateTime.Now.ToString("s", System.Globalization.CultureInfo.InvariantCulture) + Environment.NewLine +
74  "============================================================" + Environment.NewLine;
75  try
76  {
77  dump += e.ExceptionObject.ToString();
78  System.IO.File.WriteAllText(DumpFile, dump);
79  }
80  catch { }
81  }
82 
83  #endregion
84 
85  #region Static properties
86 
91  public static string DumpFile
92  {
93  get
94  {
95  if (String.IsNullOrEmpty(_dumpFile))
96  {
97  _dumpFile = System.IO.Path.Combine(
98  System.IO.Path.GetTempPath(),
99  "bovender-dump.txt");
100  }
101  return _dumpFile;
102  }
103  set
104  {
105  _dumpFile = value;
106  }
107  }
108 
109  #endregion
110 
111  #region Fields
112 
113  private static string _dumpFile;
114 
115  #endregion
116  }
117 }
static bool Manage(object origin, Exception e)
Central exception managing method; can be called in try...catch statements of user entry points...
This static class implements central exception management.
static void AppDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
Event handler for the AddDomain.CurrentDomain.UnhandledException event.