public void ToString_StringIsEqualTo_ExceptionToString() { var exception = TestHelper.GetException(); var sentryException = new SentryException(exception); string exceptionString = exception.ToString(); string stacktraceString = sentryException.ToString(); Console.WriteLine(exceptionString); Console.WriteLine(); Console.WriteLine(stacktraceString); Assert.That(stacktraceString, Is.EqualTo(exceptionString)); }
public void Emit(LogEvent logEvent) { switch (logEvent.Level) { case LogEventLevel.Verbose: case LogEventLevel.Debug: case LogEventLevel.Information: case LogEventLevel.Warning: break; case LogEventLevel.Error: case LogEventLevel.Fatal: if (logEvent.Exception == null) { break; } var exception = logEvent.Exception; SentryClient.SharedClient?.SnapshotStacktrace(() => { var logSentry = new SentryEvent(SentrySeverity.Error); var sentryException = new SentryException(exception.Message, exception.GetType().ToString()); logSentry.Logger = _logger ?? string.Empty; logSentry.Exceptions = new[] { sentryException }; if (logEvent.Exception.StackTrace != null) { logSentry.Extra = new NSDictionary <NSString, NSObject>(new NSString("MS Exception"), new NSString(logEvent.Exception.StackTrace)); } logSentry.Message = exception.Message; SentryClient.SharedClient?.AppendStacktraceToEvent(logSentry); foreach (var thread in logSentry.Threads) { if (thread == null) { continue; } thread.Crashed = 0; } SentryClient.SharedClient?.SendEvent(logSentry, null); }); break; } }
internal IEnumerable <SentryException> CreateSentryException(Exception exception) { Debug.Assert(exception != null); if (exception is AggregateException ae) { foreach (var inner in ae.InnerExceptions.SelectMany(CreateSentryException)) { yield return(inner); } } else if (exception.InnerException != null) { foreach (var inner in CreateSentryException(exception.InnerException)) { yield return(inner); } } var sentryEx = new SentryException { Type = exception.GetType()?.FullName, Module = exception.GetType()?.Assembly?.FullName, Value = exception.Message, ThreadId = Thread.CurrentThread.ManagedThreadId, Mechanism = GetMechanism(exception) }; if (exception.Data.Count != 0) { foreach (var key in exception.Data.Keys) { if (key is string keyString) { sentryEx.Data[keyString] = exception.Data[key]; } } } sentryEx.Stacktrace = SentryStackTraceFactoryAccessor().Create(exception); yield return(sentryEx); }
private async Task Send(Exception ex, string level) { try { if (ex is TaskCanceledException || ex is OperationCanceledException) { return; } if (!AppSettings.ConnectionService.IsConnectionAvailable()) { return; //TODO: need to store locale } var packet = GetPacket(); packet.Level = level; packet.Extra = new ExceptionData(ex); packet.Exceptions = SentryException.GetList(ex); await Send(packet, _dsn); } catch { //todo nothing } }
public SentryRequest(Exception exception) { Platform = "csharp"; EventId = Guid.NewGuid().ToString("N"); Timestamp = DateTimeOffset.UtcNow.ToString("o"); Tags = new Dictionary<string, string>(); Extra = new Dictionary<string, string>(); Message = exception.Message; if (exception.TargetSite != null) { Culprit = String.Format("{0} in {1}", ((exception.TargetSite.ReflectedType == null) ? "<dynamic type>" : exception.TargetSite.ReflectedType.FullName), exception.TargetSite.Name); } Exception = new List<SentryException>(); for (Exception currentException = exception; currentException != null; currentException = currentException.InnerException) { SentryException sentryException = new SentryException(currentException) { Module = currentException.Source, Type = currentException.GetType().Name, Value = currentException.Message }; Exception.Add(sentryException); } }
public void Data_Getter_NotNull() { var sut = new SentryException(); Assert.NotNull(sut.Data); }