Simply3DScan
LogException.cs
Go to the documentation of this file.
1 using System;
2 using System.Diagnostics;
3 using Logging;
4 using PostSharp.Aspects;
5 using PostSharp.Aspects.Dependencies;
6 
7 namespace SharedObjects
8 {
9  [Serializable]
10  [ProvideAspectRole("LogException")]
11  [AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.After, "Logging")]
12  public class LogException : OnExceptionAspect
13  {
19  public override void OnException(MethodExecutionArgs args)
20  {
21  Arguments arguments = args.Arguments;
22 
23  StackTrace st = new StackTrace(args.Exception, true);
24  StackFrame frame = st.GetFrame(0);
25 
26  Singleton<Logger>.Instance.LogWarning($"Call to {args.Method.Name} failed");
27  foreach (object argument in arguments)
28  Singleton<Logger>.Instance.LogWarning($"Argument: {argument}");
29 
30 
31  Singleton<Logger>.Instance.LogException(args.Exception, args.Method.Name, frame.GetFileName(), frame.GetFileLineNumber());
32  args.FlowBehavior = FlowBehavior.Continue;
33  base.OnException(args);
34  }
35  }
36 }
Class for creating a singleton for a generic class
Definition: Singleton.cs:9
Definition: Logger.cs:5
override void OnException(MethodExecutionArgs args)
Method executed after the body of methods to which this aspect is applied, in case that the method re...
Definition: LogException.cs:19
static T Instance
Gets the instance.
Definition: Singleton.cs:27