public void Setup() { _fakeRestClient = new Mock<IRestClient>(); _fakeRestClient .Setup(r => r.Put<ExceptionResponse>(It.IsAny<string>(), It.IsAny<ExceptionReport>())) .Callback<string, object>((target, report) => _submittedReport = (ExceptionReport)report); _client = new ExceptronClient(new ExceptronConfiguration { ApiKey = ApiKey }, appVersion) { RestClient = _fakeRestClient.Object }; }
public void Setup() { _report = Builder<ExceptionReport>.CreateNew() .With(c => c.stk = Builder<Frame>.CreateListOfSize(3).Build().ToList()) .Build(); }
private void SetEnviromentInfo(ExceptionReport report) { report.cul = Thread.CurrentThread.CurrentCulture.Name; try { report.os = Environment.OSVersion.VersionString; } catch (Exception) { if (Configuration.ThrowExceptions) throw; } if (Configuration.IncludeMachineName) { try { report.hn = Environment.MachineName; } catch (Exception) { if (Configuration.ThrowExceptions) throw; } } }
private void SetHttpInfo(ExceptionData exceptionData, ExceptionReport report) { if (exceptionData.HttpContext == null && HttpContext.Current == null) return; if (exceptionData.HttpContext == null) { exceptionData.HttpContext = HttpContext.Current; } try { report.hm = exceptionData.HttpContext.Request.HttpMethod; //TODO:find proper way to find http status code. /* var httpException = exceptionData.Exception as HttpException; if (httpException != null) { report.sc = httpException.GetHttpCode(); }*/ report.url = exceptionData.HttpContext.Request.Url.ToString(); report.ua = exceptionData.HttpContext.Request.UserAgent; } catch (Exception) { if (Configuration.ThrowExceptions) throw; } }
/// <summary> /// Submit an exception to exceptron Servers. /// </summary> /// <param name="exceptionData">Exception data to be reported to the server</param> public ExceptionResponse SubmitException(ExceptionData exceptionData) { try { ValidateState(exceptionData); var report = new ExceptionReport(); report.ap = Configuration.ApiKey; report.dn = ClientName; report.dv = ClientVersion; report.aver = _applicationVersion; report.ext = exceptionData.Exception.GetType().FullName; report.stk = ConvertToFrames(exceptionData.Exception); report.exm = exceptionData.Exception.Message; report.cmp = exceptionData.Component; report.uid = exceptionData.UserId; report.msg = exceptionData.Message; report.sv = (int)exceptionData.Severity; report.fv = _maxFrameworkVersion; report.ft = FrameworkType; SetHttpInfo(exceptionData, report); SetEnviromentInfo(report); var exceptionResponse = RestClient.Put<ExceptionResponse>(Configuration.Host, report); exceptionData.Exception.Data["et"] = exceptionResponse.RefId; return exceptionResponse; } catch (Exception e) { Trace.WriteLine("Unable to submit exception to exceptron. ", e.ToString()); if (Configuration.ThrowExceptions) { throw; } return new ExceptionResponse { Exception = e }; } }