public string Capture(Exception exception) { if (exception == null) { throw new ArgumentNullException(nameof(exception)); } var refId = Guid.NewGuid().ToString().ToLower(); var sentryEvent = new SentryEvent(exception); sentryEvent.Tags.Add("Referance Id:", refId); _client.Capture(sentryEvent); return(refId); }
static void Run(IRavenClient client) { client.Capture(new SentryEvent(new SentryMessage("Hello world 1900"))); client.CaptureMessage(new SentryMessage("Hello world IFNOOOOOO")); try { DivideByZero(); } catch (Exception exception) { client.Capture(new SentryEvent(exception)); } }
public static void CatchAllUnhandledException(Action <IRavenClient> action, IRavenClient ravenClent) { try { action(ravenClent); } catch (Exception ex) { ravenClent.Capture(new SentryEvent(ex)); throw; } }
protected override void LogError(HttpApplication application, Exception exception) { if (_appConfig.IsProductionEnvironment) { exception.Data.Add("request-url", application.Request.RawUrl); _ravenClient.Capture(new SentryEvent(exception)); } else { base.LogError(application, exception); } }
/// <summary> /// Appends the specified logging event. /// </summary> /// <param name="loggingEvent">The logging event.</param> protected override void Append(LoggingEvent loggingEvent) { if (RavenClient == null) { RavenClient = new RavenClient(DSN) { Logger = Logger, Release = Assembly.GetExecutingAssembly().GetName().Version.ToString(), // If something goes wrong when sending the event to Sentry, make sure this is written to log4net's internal // log. See <add key="log4net.Internal.Debug" value="true"/> ErrorOnCapture = ex => LogLog.Error(typeof(SentryAppender), "[" + Name + "] " + ex.Message, ex), }; } var tags = tagLayouts.ToDictionary(t => t.Name, t => (t.Layout.Format(loggingEvent) ?? "").ToString()); Exception exception = loggingEvent.ExceptionObject ?? loggingEvent.MessageObject as Exception; ErrorLevel level = Translate(loggingEvent.Level); SentryEvent sentryEvent; if (loggingEvent.ExceptionObject != null) { // We should capture buth the exception and the message passed sentryEvent = new SentryEvent(exception); } else if (loggingEvent.MessageObject is Exception) { // We should capture the exception with no custom message sentryEvent = new SentryEvent((Exception)loggingEvent.MessageObject); } else { // Just capture message var message = loggingEvent.RenderedMessage; sentryEvent = new SentryEvent(new SentryMessage(message, level, tags)); } sentryEvent.Extra = new { Environment = new EnvironmentExtra() }; if (loggingEvent.Level.DisplayName == "ERROR" || loggingEvent.Level.DisplayName == "FETAL") { RavenClient.Capture(sentryEvent); } else { RavenClient.CaptureAsync(sentryEvent); } }
protected override void Append(LoggingEvent loggingEvent) { if (DSN == null) { return; } var dsn = Environment.ExpandEnvironmentVariables(DSN); if (dsn.Length == 0 || dsn.Equals("%SENTRY_DSN%")) { return; } if (_ravenClient == null) { _ravenClient = new RavenClient(dsn) { Logger = Logger, ErrorOnCapture = ex => LogLog.Error(typeof(RavenAppender), ex.Message, ex) }; } var level = Translate(loggingEvent.Level); var sentryEvent = loggingEvent.ExceptionObject != null ? new SentryEvent(loggingEvent.ExceptionObject) : new SentryEvent(loggingEvent.MessageObject as string); sentryEvent.Level = level; sentryEvent.Tags = new Dictionary <string, string> { { "assembly", AppDomain.CurrentDomain.FriendlyName } }; _ravenClient.Capture(sentryEvent); }
protected override void Append(LoggingEvent loggingEvent) { if (RavenClient == null) { RavenClient = new RavenClient(DSN) { Logger = Logger, Environment = Environment, Release = Release, // If something goes wrong when sending the event to Sentry, make sure this is written to log4net's internal // log. See <add key="log4net.Internal.Debug" value="true"/> ErrorOnCapture = ex => LogLog.Error(typeof(SentryAppender), "[" + Name + "] " + ex.Message, ex) }; if (!string.IsNullOrWhiteSpace(Tags)) { string[] tags = Tags.Split('&'); foreach (string tagPair in tags) { string[] keyValue = tagPair.Split(new[] { '=' }, 2); if (keyValue.Length == 2) { Layout2RawLayoutAdapter layout = new Layout2RawLayoutAdapter(new PatternLayout(HttpUtility.UrlDecode(keyValue[1]))); AddTag(new SentryTag { Name = keyValue[0], Layout = layout }); } } } } SentryEvent sentryEvent = null; if (loggingEvent.ExceptionObject != null) { // We should capture both the exception and the message passed sentryEvent = new SentryEvent(loggingEvent.ExceptionObject) { Message = loggingEvent.RenderedMessage }; } else if (loggingEvent.MessageObject is Exception) { // We should capture the exception with no custom message sentryEvent = new SentryEvent(loggingEvent.MessageObject as Exception); } else { // Just capture message sentryEvent = new SentryEvent(loggingEvent.RenderedMessage); } // Assign error level sentryEvent.Level = Translate(loggingEvent.Level); // Format and add tags tagLayouts.ForEach(tl => sentryEvent.Tags.Add(tl.Name, (tl.Layout.Format(loggingEvent) ?? string.Empty).ToString())); // Add extra data sentryEvent.Extra = GetLoggingEventProperties(loggingEvent); RavenClient.Capture(sentryEvent); }
protected override void Append(LoggingEvent loggingEvent) { if (RavenClient == null) { RavenClient = new RavenClient(DSN) { Logger = Logger, Compression = CompressionEnabled, Environment = Environment, // If something goes wrong when sending the event to Sentry, make sure this is written to log4net's internal // log. See <add key="log4net.Internal.Debug" value="true"/> ErrorOnCapture = ex => LogLog.Error(typeof(SentryAppender), "[" + Name + "] " + ex.Message, ex) }; } var httpExtra = HttpExtra.GetHttpExtra(); object extra; if (httpExtra != null) { extra = new { Environment = new EnvironmentExtra(), Http = httpExtra }; } else { extra = new { Environment = new EnvironmentExtra() }; } var tags = _tagLayouts.ToDictionary(t => t.Name, t => (t.Layout.Format(loggingEvent) ?? "").ToString()); var exception = loggingEvent.ExceptionObject ?? loggingEvent.MessageObject as Exception; var level = Translate(loggingEvent.Level); if (loggingEvent.ExceptionObject != null) { // We should capture buth the exception and the message passed var @event = new SentryEvent(loggingEvent.RenderedMessage) { Extra = extra, Level = level, Tags = tags }; RavenClient.Capture(@event); } else if (loggingEvent.MessageObject is Exception) { // We should capture the exception with no custom message var @event = new SentryEvent(exception) { Extra = extra, Level = level, Tags = tags }; RavenClient.Capture(@event); } else { // Just capture message var message = loggingEvent.RenderedMessage; if (message != null) { var @event = new SentryEvent(loggingEvent.RenderedMessage) { Extra = extra, Level = level, Tags = tags }; RavenClient.Capture(@event); } } }