From c11ef7e37e1f5821eb12578c4632012780ab1a50 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Wed, 9 Jan 2019 01:37:01 +1300 Subject: [PATCH] Updates SentryAbstractLogger to take in SentryClient. --- .../SentryAbstractLogger.cs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryAbstractLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryAbstractLogger.cs index b008226..b84263e 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryAbstractLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryAbstractLogger.cs @@ -17,28 +17,28 @@ namespace Vima.LoggingAbstractor.Sentry /// public class SentryAbstractLogger : AbstractLoggerBase, ISentryAbstractLogger { - private readonly IHub _hub; + private readonly ISentryClient _sentryClient; /// /// Initializes a new instance of the class. /// - /// The Sentry hub. + /// The Sentry client. /// The minimal logging level. - public SentryAbstractLogger(IHub hub, LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose) + public SentryAbstractLogger(ISentryClient sentryClient, LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose) : base(new AbstractLoggerSettings { MinimalLoggingLevel = minimalLoggingLevel }) { - _hub = hub ?? throw new ArgumentNullException(nameof(hub)); + _sentryClient = sentryClient ?? throw new ArgumentNullException(nameof(sentryClient)); } /// /// Initializes a new instance of the class. /// - /// The Sentry hub. + /// The Sentry client. /// The logger's settings. - public SentryAbstractLogger(IHub hub, AbstractLoggerSettings settings) + public SentryAbstractLogger(ISentryClient sentryClient, AbstractLoggerSettings settings) : base(settings ?? throw new ArgumentNullException(nameof(settings))) { - _hub = hub ?? throw new ArgumentNullException(nameof(hub)); + _sentryClient = sentryClient ?? throw new ArgumentNullException(nameof(sentryClient)); } /// @@ -54,12 +54,8 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn return; } - _hub.WithScope(scope => - { - SetupSentryScope(scope, loggingLevel, parameters); - - _hub.CaptureMessage(message); - }); + var scope = CreateSentryScope(loggingLevel, parameters); + _sentryClient.CaptureEvent(new SentryEvent { Message = message }, scope); } /// @@ -75,12 +71,8 @@ public override void TraceException(Exception exception, LoggingLevel loggingLev return; } - _hub.WithScope(scope => - { - SetupSentryScope(scope, loggingLevel, parameters); - - _hub.CaptureException(exception); - }); + var scope = CreateSentryScope(loggingLevel, parameters); + _sentryClient.CaptureEvent(new SentryEvent(exception), scope); } private static Dictionary GenerateTags(IEnumerable parameters) @@ -88,10 +80,12 @@ private static Dictionary GenerateTags(IEnumerable tag); } - private void SetupSentryScope(BaseScope scope, LoggingLevel loggingLevel, IEnumerable parameters) + private Scope CreateSentryScope(LoggingLevel loggingLevel, IEnumerable parameters) { var loggingParameters = GetGlobalAndLocalLoggingParameters(parameters); Dictionary tags = GenerateTags(loggingParameters); + + var scope = new Scope(new SentryOptions()); scope.SetTags(tags); scope.Level = LoggingLevelMapper.ConvertLoggingLevelToSentryLevel(loggingLevel); @@ -107,6 +101,8 @@ private void SetupSentryScope(BaseScope scope, LoggingLevel loggingLevel, IEnume { scope.SetExtra($"Extra #{extraCount++}", data); } + + return scope; } } }