/// <summary>Collect information</summary> /// <param name="context">Context information provided by the class which reported the error.</param> /// <returns>Collection. Items with multiple values are joined using <c>";;"</c></returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { var myHeaders = new NameValueCollection(HttpContext.Current.Request.Headers); myHeaders["Url"] = HttpContext.Current.Request.Url.ToString(); return(new ContextCollectionDTO("HttpHeaders", myHeaders)); }
/// <summary> /// Collect context information from all context providers. /// </summary> /// <param name="context"> /// CreateReport context (specialized for the different report adapters, for instance the ASP.NET /// adapter contains the current <c>HttpContext</c>) /// </param> /// <remarks> /// <para> /// Collections are added to the <c>context.ContextCollections</c> property. /// </para> /// </remarks> /// <exception cref="System.ArgumentNullException">context</exception> public void Collect(IErrorReporterContext context) { if (context == null) { throw new ArgumentNullException("context"); } foreach (var provider in _providers) { try { var item = provider.Collect(context); if (item == null) { continue; } context.ContextCollections.Add(item); } catch (Exception exception) { var item = new ContextCollectionDTO(provider.Name, new Dictionary <string, string> { { "Error", exception.ToString() } }); context.ContextCollections.Add(item); } } }
/// <summary> /// Collect information /// </summary> /// <param name="context"></param> /// <returns>Collection</returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { if (HttpContext.Current.Session == null) { return(new ContextCollectionDTO("HttpSession", new NameValueCollection())); } var items = new NameValueCollection(); foreach (string key in HttpContext.Current.Session) { var item = HttpContext.Current.Session[key]; if (item is string) { items.Add(key, (string)item); } else { var json = JsonConvert.SerializeObject(item); items.Add(key, json); } } return(new ContextCollectionDTO("HttpSession", items)); }
public ContextCollectionDTO Collect(IErrorReporterContext context) { if (!(context is NServiceBusContext ctx)) { return(null); } if (ctx.Body != null) { var converter = new ObjectToContextCollectionConverter(); var properties = converter.ConvertToDictionary("Body", ctx.Body); properties.Add("MessageType", ctx.Body.GetType().FullName); return(new ContextCollectionDTO(Name, properties)); } var body = ctx.RawBody?.Length < 50000 ? string.Join(", ", ctx.RawBody) : "[Too large message]"; var props = new Dictionary <string, string> { { "Bytes", body } }; if (ctx.MessageType != null) { props.Add("MessageType", ctx.MessageType.FullName); } return(new ContextCollectionDTO(Name, props)); }
/// <summary> /// Collect information /// </summary> /// <param name="context">Context information provided by the class which reported the error.</param> /// <returns> /// Collection. Items with multiple values are joined using <c>";;"</c> /// </returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { var values = new Dictionary <string, string>(); var invocationRequired = false; foreach (Form form in Application.OpenForms) { if (form.InvokeRequired) { invocationRequired = true; } } if (invocationRequired || !Application.MessageLoop) { return(new ContextCollectionDTO(Name, new Dictionary <string, string> { { "Error", "Collection on non-UI thread" } })); } try { return(Collect(values)); } catch (Exception exception) { return(new ContextCollectionDTO(Name, new Dictionary <string, string> { { "Error", "Collection on non-UI thread" }, { "Exception", exception.ToString() } })); } }
/// <summary> /// Collect information /// </summary> /// <param name="context">Context information provided by the class which reported the error.</param> /// <returns> /// Collection. Items with multiple values are joined using <c>";;"</c> /// </returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { var info = new ContextCollectionDTO(Name); info.Properties.Add("WorkingSet", Environment.WorkingSet.ToString(CultureInfo.InvariantCulture)); info.Properties.Add("CurrentDirectory", Environment.CurrentDirectory); try { var process = Process.GetCurrentProcess(); info.Properties.Add("ThreadCount", process.Threads.Count.ToString(CultureInfo.InvariantCulture)); info.Properties.Add("StartTime", process.StartTime.ToString(CultureInfo.InvariantCulture)); info.Properties.Add("TotalProcessorTime", process.TotalProcessorTime.ToString()); info.Properties.Add("UserProcessorTime", process.UserProcessorTime.ToString()); info.Properties.Add("HandleCount", process.HandleCount.ToString(CultureInfo.InvariantCulture)); info.Properties.Add("ProcessName", process.ProcessName); info.Properties.Add("MainModule", process.MainModule.ToString()); info.Properties.Add("BasePriority", process.BasePriority.ToString(CultureInfo.InvariantCulture)); info.Properties.Add("VirtualMemorySize", process.VirtualMemorySize64.ToString(CultureInfo.InvariantCulture)); info.Properties.Add("PrivateMemorySize", process.PrivateMemorySize64.ToString(CultureInfo.InvariantCulture)); } catch (Exception ex) { info.Properties.Add("CollectionException", "Failed to fetch process info: " + ex); } return(info); }
/// <summary> /// Collects information from <c>Thread.CurrentThread</c> to a context called "Thread". /// </summary> /// <param name="context">Contains information about the currently processed exception and where it came from.</param> /// <returns>generated context info</returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { var info = new ContextCollectionDTO(NAME); try { info.Properties.Add("Culture", Thread.CurrentThread.CurrentUICulture.IetfLanguageTag); info.Properties.Add("Id", Thread.CurrentThread.ManagedThreadId.ToString(CultureInfo.InvariantCulture)); info.Properties.Add("Name", Thread.CurrentThread.Name); info.Properties.Add("IsBackground", Thread.CurrentThread.IsBackground.ToString(CultureInfo.InvariantCulture)); if (Thread.CurrentThread.ExecutionContext != null) { info.Properties.Add("ExecutionContext", Thread.CurrentThread.ExecutionContext.ToString()); } info.Properties.Add("Priority", Thread.CurrentThread.Priority.ToString()); info.Properties.Add("ThreadState", Thread.CurrentThread.ThreadState.ToString()); info.Properties.Add("UICulture", Thread.CurrentThread.CurrentCulture.IetfLanguageTag); } catch (Exception ex) { info.Properties.Add("CollectionException", "Failed to fetch thread info: " + ex); } return(info); }
/// <inheritdoc /> public ContextCollectionDTO Collect(IErrorReporterContext context) { if (!(context is IContextWithLogEntries logCtx)) { return(null); } RemoveOldEntries(); lock (Logs) { if (!Logs.Any()) { return(null); } if (logCtx.LogEntries?.Length > 0) { var entries = logCtx.LogEntries.ToList(); entries.AddRange(Logs); logCtx.LogEntries = entries .OrderBy(x => x.TimestampUtc) .ToArray(); } else { logCtx.LogEntries = Logs.ToArray(); } return(null); } }
private void InvokePartitionCollection(IErrorReporterContext context) { var ctx2 = context as IErrorReporterContext2; if (ctx2 == null) { return; } var col = new ErrPartitionContextCollection(); ctx2.ContextCollections.Add(col); var partitionContext = new PartitionContext(col, ctx2); foreach (var callback in _configuration.PartitionCallbacks) { try { callback(partitionContext); } catch (Exception ex) { col.Properties.Add("PartitionCollection.Err", $"Callback {callback} failed: {ex}"); } } }
/// <summary>Collect information</summary> /// <param name="context">Context information provided by the class which reported the error.</param> /// <returns>Collection named <c>Application</c>. Items with multiple values are joined using <c>";;"</c></returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { var items = new Dictionary <string, string>(); foreach (var key in HttpContext.Current.Application.AllKeys) { var value = HttpContext.Current.Application[key]; if (value == null) { items[key] = "null"; continue; } if (value.GetType().IsPrimitive || value.GetType() == typeof(string)) { items[key] = value.ToString(); } try { items[key] = JsonConvert.SerializeObject(value); } catch (Exception ex) { items[key + ".Error"] = ex.ToString(); } } if (items.Count == 0) { return(null); } return(new ContextCollectionDTO("Application", items)); }
/// <summary> /// Build an report, but do not upload it /// </summary> /// <param name="context"> /// context passed to all context providers when collecting information. This context is typically /// implemented by one of the integration libraries to provide more context that can be used to process the /// environment. /// </param> /// <remarks> /// <para> /// Will collect context info and generate a report. /// </para> /// </remarks> /// <exception cref="ArgumentNullException">exception;contextData</exception> public ErrorReportDTO Build(IErrorReporterContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Exception is CoderrClientException) { return(null); } if (IsReported(context.Exception)) { return(null); } ErrorReporterContext.MoveCollectionsInException(context.Exception, context.ContextCollections); InvokePreProcessor(context); _configuration.ContextProviders.Collect(context); // Invoke partition collection AFTER other context info providers // since those other collections might provide the property that // we want to create partions on. InvokePartitionCollection(context); var reportId = ReportIdGenerator.Generate(context.Exception); AddAddemblyVersion(context.ContextCollections); var report = new ErrorReportDTO(reportId, new ExceptionDTO(context.Exception), context.ContextCollections.ToArray()); return(report); }
public ContextCollectionDTO Collect(IErrorReporterContext context) { if (!(context is NServiceBusContext ctx)) { return(null); } var props = new Dictionary <string, string>(); if (ctx.HandlerType != null) { props.Add("Type", ctx.HandlerType.FullName); } if (ctx.HandlerInstance != null) { var handlerProps = ctx.HandlerInstance.GetType() .GetFields(BindingFlags.NonPublic | BindingFlags.Instance); foreach (var fieldInfo in handlerProps) { props.Add(fieldInfo.Name, fieldInfo.GetValue(ctx.HandlerInstance)?.ToString() ?? "null"); } } return(props.Count == 0 ? null : new ContextCollectionDTO(Name, props)); }
/// <summary> /// Generate an error report /// </summary> /// <param name="context">context</param> /// <returns>Report if it can be processed; otherwise <c>null</c>.</returns> /// <exception cref="ArgumentNullException"></exception> public static ErrorReportDTO GenerateReport(IErrorReporterContext context) { if (context == null) { throw new ArgumentNullException("context"); } return(_exceptionProcessor.Build(context)); }
/// <summary> /// Collect information /// </summary> /// <param name="context"></param> /// <returns>Collection</returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { if (HttpContext.Current == null || HttpContext.Current.Request.QueryString.Count == 0) { return(null); } return(new ContextCollectionDTO("HttpQueryString", HttpContext.Current.Request.QueryString)); }
/// <summary>Collect information</summary> /// <param name="context">Context information provided by the class which reported the error.</param> /// <returns>Collection. Items with multiple values are joined using <c>";;"</c></returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { if (HttpContext.Current.Items.Count == 0) { return(null); } return(HttpContext.Current.Items.ToContextCollection("HttpContextItems")); }
/// <summary> /// Collects the identity name. /// </summary> /// <param name="context">Context collection</param> /// <returns>Generated collection</returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { var contextInfo = new Dictionary <string, string> { { "Name", Thread.CurrentPrincipal.Identity.Name } }; return(new ContextCollectionDTO(Name, contextInfo)); }
/// <summary> /// Collect information /// </summary> /// <param name="context"></param> /// <returns>Collection</returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { if (HttpContext.Current == null || HttpContext.Current.Request.Form.Count == 0) { return(null); } return(new ContextCollectionDTO("HttpForm", HttpContext.Current.Request.Form)); }
/// <summary> /// Generate an error report /// </summary> /// <param name="context">context</param> /// <returns>generated report</returns> /// <exception cref="ArgumentNullException"></exception> public static ErrorReportDTO GenerateReport(IErrorReporterContext context) { if (context == null) { throw new ArgumentNullException("context"); } ErrorReporterContext.MoveCollectionsInException(context.Exception, context.ContextCollections); return(_exceptionProcessor.Build(context)); }
public ContextCollectionDTO Collect(IErrorReporterContext context) { var dict = new Dictionary <string, string> { { "InstallationId", _installationId }, { "ContactEmail", _contactEmail } }; return(new ContextCollectionDTO("CustomerInfo", dict)); }
/// <summary> /// Collect information /// </summary> /// <param name="context"></param> /// <returns>Collection</returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { var aspContext = context as AspNetContext; if (aspContext == null || aspContext.HttpContext.Request.Form.Count == 0) { return(null); } return(new ContextCollectionDTO("HttpForm", aspContext.HttpContext.Request.Form)); }
/// <summary> /// Collect information /// </summary> /// <param name="context"></param> /// <returns>Collection</returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { if (HttpContext.Current.Session == null || HttpContext.Current.Session.Count == 0) { return(null); } var converter = new ObjectToContextCollectionConverter(); return(converter.Convert("HttpSession", HttpContext.Current.Session)); }
/// <summary>Collect information</summary> /// <param name="context">Context information provided by the class which reported the error.</param> /// <returns>Collection. Items with multiple values are joined using <c>";;"</c></returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { var files = new Dictionary <string, string>(); foreach (string key in HttpContext.Current.Request.Files) { var file = HttpContext.Current.Request.Files[key]; files[file.FileName] = string.Format(file.ContentType + ";length=" + file.ContentLength); } return(new ContextCollectionDTO("HttpRequestFiles", files)); }
/// <summary> /// Process exception. /// </summary> /// <param name="context"> /// Used to reports (like for ASP.NET) can attach information which can be used during the context /// collection pipeline. /// </param> /// <remarks> /// <para> /// Will collect context info, generate a report, go through filters and finally upload it. /// </para> /// </remarks> /// <returns> /// Report if filter allowed the generated report; otherwise <c>null</c>. /// </returns> /// <seealso cref="IReportFilter" /> public ErrorReportDTO Process(IErrorReporterContext context) { var contextInfo = _configuration.ContextProviders.Collect(context); var reportId = ReportIdGenerator.Generate(context.Exception); var report = new ErrorReportDTO(reportId, new ExceptionDTO(context.Exception), contextInfo.ToArray()); var canUpload = _configuration.FilterCollection.CanUploadReport(report); if (!canUpload) { return(null); } return(report); }
/// <summary> /// Report an exception using a custom context /// </summary> /// <param name="reporterContext">Context used to be able to collect context information</param> /// <param name="errorContextModel">Extra context collection(s).</param> public static void Report(IErrorReporterContext reporterContext, object errorContextModel) { if (reporterContext == null) { throw new ArgumentNullException(nameof(reporterContext)); } ErrorReporterContext.MoveCollectionsInException(reporterContext.Exception, reporterContext.ContextCollections); var collection = errorContextModel.ToContextCollection(); reporterContext.ContextCollections.Add(collection); _exceptionProcessor.Process(reporterContext); }
/// <summary> /// Get or create our collection /// </summary> /// <param name="context">context to find the collection in</param> /// <returns>collection</returns> public static ContextCollectionDTO GetCoderrCollection(this IErrorReporterContext context) { var collection = context.ContextCollections.FirstOrDefault(x => x.Name == "CoderrData"); if (collection != null) { return(collection); } collection = new ContextCollectionDTO("CoderrData"); context.ContextCollections.Add(collection); return(collection); }
/// <inheritdoc /> public ContextCollectionDTO Collect(IErrorReporterContext context) { var aspNetContext = context as AspNetMvcContext; if (aspNetContext?.TempData == null || aspNetContext.TempData.Count == 0) { return(null); } var converter = new ObjectToContextCollectionConverter(); return(converter.Convert(Name, aspNetContext.TempData)); }
/// <summary> /// Add a new partition /// </summary> /// <param name="context">context</param> /// <param name="partitionName">partition</param> /// <param name="partitionKey">partitionKey</param> /// <remarks> /// <para> /// What partitions are depends on your application. It can be tenants, server clusters, users. By adding /// partitions, codeRR can /// tell you what impact the exception has on your system. /// </para> /// </remarks> public static void AddPartition(this IErrorReporterContext context, string partitionName, string partitionKey) { if (partitionName == null) { throw new ArgumentNullException(nameof(partitionName)); } if (partitionKey == null) { throw new ArgumentNullException(nameof(partitionKey)); } var collection = context.GetCoderrCollection(); collection.Properties.Add($"ErrPartition.{partitionName}", partitionKey); }
private void MoveCollectionsFromContext(IErrorReporterContext context, IList <ContextCollectionDTO> destination) { var ctx2 = context as IErrorReporterContext2; if (ctx2 == null) { return; } foreach (var col in ctx2.ContextCollections) { destination.Add(col); } ctx2.ContextCollections.Clear(); }
/// <inheritdoc /> public ContextCollectionDTO Collect(IErrorReporterContext context) { var aspNetContext = context as AspNetMvcContext; if (aspNetContext?.ViewBag == null) { return(null); } var converter = new ObjectToContextCollectionConverter(); var collection = converter.Convert(Name, aspNetContext.ViewBag); //not beatiful, but we do not want to reflect the object twice return(collection.Properties.Count == 0 ? null : collection); }
/// <summary> /// Collect information /// </summary> /// <param name="context">Context information provided by the class which reported the error.</param> /// <returns> /// Collection /// </returns> public ContextCollectionDTO Collect(IErrorReporterContext context) { var contextCollection = new NameValueCollection(); try { var collector = new ManagementCollector(contextCollection); collector.Collect("Win32_StartupCommand"); } catch (Exception exception) { contextCollection.Add("CollectionException", exception.ToString()); } return(new ContextCollectionDTO("StartupCommands", contextCollection)); }