/// <summary> /// Creates a exception information payload based on an exception /// </summary> /// <param name="exception">The exception to base the payload on</param> /// <param name="callTrace">The call stack trace, or null if its not available</param> /// <param name="config">The configuration to use</param> /// <returns>The exception information payload to use in the notification</returns> public static ExceptionInfo GenerateExceptionInfo(Exception exception, StackTrace callTrace, Configuration config) { if (exception == null) return null; StackTrace trace = null; // Attempt to get stack frame from exception, if the stack trace is invalid, // try to use the call stack trace trace = new StackTrace(exception, true); if (trace == null || trace.FrameCount == 0) { // If we still don't have a stack trace we can use, give up and return if (callTrace == null || callTrace.FrameCount == 0) return null; trace = callTrace; } // Attempt to get the stack frames var frames = trace.GetFrames(); if (frames == null) return null; // Convert the frames to stack frame payloads var stackFrameInfos = frames.Select(x => GenerateStackTraceFrameInfo(x, config)) .Where(x => !x.Method.StartsWith("Bugsnag.")).ToList(); return new ExceptionInfo { ExceptionClass = exception.GetType().Name, Description = exception.Message, StackTrace = stackFrameInfos }; }
/// <summary> /// Creates a stack frame information payload to use in notifications /// </summary> /// <param name="frame">The stack frame to base the payload on</param> /// <param name="config">The configuration to use</param> /// <returns>The stack frame payload to use in notifications</returns> public static StackTraceFrameInfo GenerateStackTraceFrameInfo(StackFrame frame, Configuration config) { if (frame == null || config == null) return null; // Get the filename the frame comes from without prefixes var file = config.RemoveFileNamePrefix(frame.GetFileName()); // Mark the frame is In Project if we are autodetecting and there is a filename, or // the method comes from the configured project namespaces. var method = frame.GetMethod(); var inProject = (config.AutoDetectInProject && !string.IsNullOrEmpty(file)) || (method.DeclaringType != null && config.IsInProjectNamespace(method.DeclaringType.FullName)); return new StackTraceFrameInfo { File = file, LineNumber = frame.GetFileLineNumber(), Method = GenerateMethodSignature(method), InProject = inProject }; }
public NotificationFactory(Configuration config) { Config = config; }
public Notifier(Configuration config) { Config = config; Factory = new NotificationFactory(config); }