public void Log(SentryLevel logLevel, string?message, Exception?exception = null, params object?[] args) { if (!IsEnabled(logLevel)) { return; } switch (logLevel) { case SentryLevel.Debug or SentryLevel.Info: Debug.Log(GetLog()); break; case SentryLevel.Warning: Debug.LogWarning(GetLog()); break; case SentryLevel.Error or SentryLevel.Fatal: Debug.LogError(GetLog()); break; default: Debug.Log(GetLog()); break; } string GetLog() { var log = $"{LogPrefix}({logLevel}) {Format(message, args)} {exception}"; _interceptor?.Intercept(logLevel, log); return(log); } }
public void Log(SentryLevel logLevel, string message, Exception exception = null, params object[] args) { switch (logLevel) { case SentryLevel.Fatal: InternalLogger.Fatal(exception, message, args); break; case SentryLevel.Error: InternalLogger.Error(exception, message, args); break; case SentryLevel.Warning: InternalLogger.Warn(exception, message, args); break; case SentryLevel.Info: InternalLogger.Info(exception, message, args); break; default: InternalLogger.Debug(exception, message, args); break; } if (_extraLogger?.IsEnabled(logLevel) == true) { _extraLogger.Log(logLevel, message, exception, args); } }
public Entry(SentryLevel level, string message, Exception exception, object[] args) { Level = level; Message = message; Exception = exception; Args = args; }
public SpeckleException(string message, bool log = true, SentryLevel level = SentryLevel.Info) : base(message) { if (log) { Log.CaptureException(this, level); } }
public TestOutputDiagnosticLogger( ITestOutputHelper testOutputHelper, SentryLevel minimumLevel = SentryLevel.Debug) { _testOutputHelper = testOutputHelper; _minimumLevel = minimumLevel; }
//capture and make sure Sentry is initialized public static void CaptureException( Exception e, SentryLevel level = SentryLevel.Info, List <KeyValuePair <string, object> > extra = null) { Initialize(); SentrySdk.WithScope(s => { s.Level = level; if (extra != null) { s.SetExtras(extra); } if (e is AggregateException aggregate) { aggregate.InnerExceptions.ToList().ForEach(ex => SentrySdk.CaptureException(e)); } else { SentrySdk.CaptureException(e); } }); }
public void Log(SentryLevel logLevel, string message, Exception exception = null, params object[] args) { var logMessage = $"SENTRY: {string.Format(message, args)}"; switch (logLevel) { case SentryLevel.Debug: _logger.Debug(logMessage); break; case SentryLevel.Info: _logger.Info(logMessage); break; case SentryLevel.Warning: _logger.Warn(logMessage); break; case SentryLevel.Error: _logger.Error(logMessage); break; case SentryLevel.Fatal: _logger.Fatal(logMessage); break; } }
/// <summary> /// Log an internal SDK message. /// </summary> internal static void Log( this SentryOptions options, SentryLevel logLevel, string message, Exception?exception = null, params object?[] args) => options.DiagnosticLogger?.Log(logLevel, message, exception, args);
/// <summary> /// Logs the message. /// </summary> public void Log(SentryLevel logLevel, string message, Exception exception = null, params object[] args) { if (!IsEnabled(logLevel)) { return; } _logger.Log(logLevel.ToMicrosoft(), exception, message, args); }
public SpeckleException(string message, GraphQLError[] errors, bool log = true, SentryLevel level = SentryLevel.Info) : base(message) { GraphQLErrors = errors.Select(error => new KeyValuePair <string, object>("error", error.Message)).ToList(); if (log) { Log.CaptureException(this, level, GraphQLErrors); } }
public void Log(SentryLevel logLevel, string message, Exception exception = null, params object[] args) { var formattedMessage = string.Format(message, args); _testOutputHelper.WriteLine($@" [{logLevel}]: {formattedMessage} Exception: {exception?.ToString() ?? "<none>"} ".Trim()); }
public void Log_LoggerLevel_Set() { const SentryLevel expectedLevel = SentryLevel.Error; var logger = _fixture.GetLogger(); logger.Error(DefaultMessage); _fixture.Hub.Received(1) .CaptureEvent(Arg.Is <SentryEvent>(e => e.Level == expectedLevel)); }
internal static void LogIfEnabled( this IDiagnosticLogger logger, SentryLevel level, string message, Exception?exception = null) { if (logger.IsEnabled(level)) { logger.Log(level, message, exception); } }
private static string ToNativeDiagnosticLevel(SentryLevel sentryLevel) { return(sentryLevel switch { SentryLevel.Debug => "debug", SentryLevel.Info => "info", SentryLevel.Warning => "warning", SentryLevel.Error => "error", SentryLevel.Fatal => "fatal", _ => "none" });
public SpeckleException(string message, Exception inner, bool log = true, SentryLevel level = SentryLevel.Info) : base(message, inner) { if (inner is SpeckleException) { return; } if (log) { Log.CaptureException(this, level); } }
internal static void LogIfEnabled <TArg>( this IDiagnosticLogger logger, SentryLevel level, Exception?exception, string message, TArg arg) { if (logger.IsEnabled(level)) { logger.Log(level, message, exception, arg); } }
internal static void LogIfEnabled <TArg, TArg2>( this IDiagnosticLogger logger, SentryLevel level, string message, TArg arg, TArg2 arg2, Exception exception = null) { if (logger?.IsEnabled(level) == true) { logger.Log(level, message, exception, arg, arg2); } }
public void Apply_Level_NotOnTarget_SetFromSource() { const SentryLevel expected = SentryLevel.Fatal; var sut = _fixture.GetSut(); sut.Level = expected; var target = _fixture.GetSut(); sut.Apply(target); Assert.Equal(expected, target.Level); }
public void Apply_Level_OnTarget_NotOverwritten() { const SentryLevel expected = SentryLevel.Fatal; var sut = _fixture.GetSut(); var target = _fixture.GetSut(); target.Level = expected; sut.Level = SentryLevel.Info; sut.Apply(target); Assert.Equal(expected, target.Level); }
public void Log_LowerLevelThanInitializationLevel_DisablesLogger(SentryLevel initializationLevel, SentryLevel lowerLevel) { var interceptor = new TestUnityLoggerInterceptor(); var logger = new UnityLogger(new SentryOptions { DiagnosticLevel = initializationLevel }, interceptor); const string expectedLog = "Some log"; logger.Log(lowerLevel, expectedLog); Assert.False(logger.IsEnabled(lowerLevel)); Assert.False(interceptor.LogMessage.Contains(expectedLog)); }
/// <summary> /// Captures a message with a configurable scope callback. /// </summary> /// <param name="hub">The Sentry hub.</param> /// <param name="message">The message to send.</param> /// <param name="configureScope">The callback to configure the scope.</param> /// <param name="level">The message level.</param> /// <returns>The Id of the event</returns> public static SentryId CaptureMessage( this IHub hub, string message, Action <Scope> configureScope, SentryLevel level = SentryLevel.Info) => !hub.IsEnabled || string.IsNullOrWhiteSpace(message) ? new SentryId() : hub.CaptureEvent( new SentryEvent { Message = message, Level = level }, configureScope);
public void Sink_LoggerLevel_Set() { const SentryLevel expectedLevel = SentryLevel.Error; var sut = _fixture.GetSut(); var evt = new LogEvent(DateTimeOffset.UtcNow, LogEventLevel.Error, null, MessageTemplate.Empty, Enumerable.Empty <LogEventProperty>()); sut.Emit(evt); _fixture.Hub.Received(1) .CaptureEvent(Arg.Is <SentryEvent>(e => e.Level == expectedLevel)); }
public async Task InvokeAsync_OptionsConfigureScope_AffectsAllRequests() { const SentryLevel expected = SentryLevel.Debug; _fixture.Options.ConfigureScope(s => s.Level = expected); _fixture.RequestDelegate = context => throw new Exception(); var sut = _fixture.GetSut(); await Assert.ThrowsAsync <Exception>(async() => await sut.InvokeAsync(_fixture.HttpContext)); _fixture.Client.Received(1).CaptureEvent( Arg.Any <SentryEvent>(), Arg.Is <Scope>(e => e.Level == expected)); }
/// <summary> /// Captures a message. /// </summary> /// <param name="client">The Sentry client.</param> /// <param name="message">The message to send.</param> /// <param name="level">The message level.</param> /// <returns>The Id of the event</returns> public static SentryId CaptureMessage( this ISentryClient client, string message, SentryLevel level = SentryLevel.Info) { return(!client.IsEnabled || string.IsNullOrWhiteSpace(message) ? new SentryId() : client.CaptureEvent(new SentryEvent { Message = message, Level = level })); }
public void Append_LoggerNameAndLevel_Set() { const string expectedLogger = "logger"; const SentryLevel expectedLevel = SentryLevel.Error; var sut = _fixture.GetSut(); var evt = new LoggingEvent(null, null, expectedLogger, Level.Error, null, null); sut.DoAppend(evt); _ = _fixture.Hub.Received(1) .CaptureEvent(Arg.Is <SentryEvent>(e => e.Logger == expectedLogger && e.Level == expectedLevel)); }
public bool IsEnabled(SentryLevel level) { if (_extraLogger?.IsEnabled(level) == true) { return(true); } return(level switch { SentryLevel.Fatal => InternalLogger.IsFatalEnabled, SentryLevel.Error => InternalLogger.IsErrorEnabled, SentryLevel.Warning => InternalLogger.IsWarnEnabled, SentryLevel.Info => InternalLogger.IsInfoEnabled, _ => InternalLogger.IsDebugEnabled });
//capture and make sure Sentry is initialized public static void CaptureException( Exception e, SentryLevel level = SentryLevel.Error, List <KeyValuePair <string, object> > extra = null) { Instance(); SentrySdk.WithScope(s => { s.Level = level; if (extra != null) { s.SetExtras(extra); } SentrySdk.CaptureException(e); }); }
internal static void LogIfEnabled( this SentryOptions options, SentryLevel level, Exception?exception, string message) { var logger = options.DiagnosticLogger; if (logger == null) { return; } if (logger.IsEnabled(level)) { logger.Log(level, message, exception); } }
public void Log_DebugLevels_Correspond([Values] SentryLevel sentryLevel) { LogAssert.ignoreFailingMessages = true; var interceptor = new TestUnityLoggerInterceptor(); var logger = new UnityLogger(new SentryOptions { DiagnosticLevel = sentryLevel }, interceptor); const string expectedLog = "Some log"; logger.Log(sentryLevel, expectedLog); Assert.True(logger.IsEnabled(sentryLevel)); Assert.True(interceptor.LogMessage.Contains("Sentry")); Assert.True(interceptor.LogMessage.Contains(expectedLog)); Assert.True(interceptor.LogMessage.Contains(sentryLevel.ToString())); }
public void TestLoggingToSentry() { SentryLevel lErrorLevel = SentryLevel.Debug; IDictionary <string, string> lTags = null; Exception lException = null; var sentryClient = new Mock <ISentryClient>(); sentryClient .Setup(x => x.CaptureException(It.IsAny <Exception>())) .Callback((Exception exception, SentryEvent msg, SentryLevel lvl, IDictionary <string, string> d, object extra) => { lException = exception; lErrorLevel = lvl; lTags = d; }) .Returns(new SentryId()); // Setup NLog var sentryTarget = new SentryTarget() { Dsn = "https://[email protected]/1337801", }; var configuration = new LoggingConfiguration(); configuration.AddTarget("NLogSentry", sentryTarget); configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, sentryTarget)); LogManager.Configuration = configuration; try { throw new Exception("Oh No!"); } catch (Exception e) { var logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Error Message", e); } Assert.IsTrue(lException.Message == "Oh No!"); Assert.IsTrue(lTags == null); Assert.IsTrue(lErrorLevel == SentryLevel.Error); }