public async Task ExecuteCommand(AppGetOption option) { var commandDic = option.ToDictionary(); foreach (var pair in commandDic) { SentryTarget.AddTag(pair.Key, pair.Value); } if (option.Verbose) { LogConfigurator.EnableVerboseLogging(); } var commandHandler = _handlers.Single(c => c.Key == option.GetType()).Value.Value; if (commandHandler == null) { throw new UnknownCommandException(option); } _logger.Debug("Starting command [{0}]", option.CommandName); var stopwatch = Stopwatch.StartNew(); await commandHandler.Execute(option); stopwatch.Stop(); Console.WriteLine(); _logger.Debug("Completed command [{0}]. took: {1:N}s", option.CommandName, stopwatch.Elapsed.TotalSeconds); }
/// <summary> /// Adds a target for Sentry to the NLog configuration. /// </summary> /// <param name="configuration">The NLog configuration.</param> /// <param name="dsn"> The sentry DSN.</param> /// <param name="targetName"> The name to give the new target.</param> /// <param name="optionsConfig">An optional action for configuring the Sentry target options.</param> /// <returns>The configuration.</returns> public static LoggingConfiguration AddSentry(this LoggingConfiguration configuration, string dsn, string targetName, Action <SentryNLogOptions> optionsConfig = null) { var options = new SentryNLogOptions(); optionsConfig?.Invoke(options); Target.Register <SentryTarget>("Sentry"); var target = new SentryTarget(options) { Name = targetName, Layout = "${message}", }; if (dsn != null && options.Dsn == null) { options.Dsn = new Dsn(dsn); } configuration?.AddTarget(targetName, target); configuration?.AddRuleForAllLevels(targetName); return(configuration); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = "https://[email protected]/10"; } else { dsn = RuntimeInfo.IsProduction ? "https://[email protected]/2" : "https://[email protected]/9"; } var target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Debug, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); // Events logged to Sentry go only to Sentry. var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, target) { Final = true }; LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = "https://[email protected]/5"; } else { dsn = RuntimeInfo.IsProduction ? "https://[email protected]/3" : "https://[email protected]/4"; } var target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Debug, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); // Events logged to Sentry go only to Sentry. var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, target) { Final = true }; LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = "https://[email protected]/1339335"; } else { dsn = RuntimeInfo.IsProduction ? "https://[email protected]/209545" : "https://[email protected]/227247"; } var target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Debug, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); // Events logged to Sentry go only to Sentry. var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, target) { Final = true }; LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = "https://[email protected]/29"; } else { dsn = RuntimeInfo.IsProduction ? "https://[email protected]/27" : "https://[email protected]/30"; } var target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Debug, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); // Events logged to Sentry go only to Sentry. var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, target) { Final = true }; LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = "https://[email protected]/20"; } else { dsn = RuntimeInfo.IsProduction ? "https://[email protected]/15" : "https://[email protected]/16"; } var target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Debug, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); // Events logged to Sentry go only to Sentry. var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, target) { Final = true }; LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); }
public Target GetTarget(Action <SentryNLogOptions> customConfig = null, bool asyncTarget = false) { var options = Options; if (customConfig != null) { options = new SentryNLogOptions(); customConfig(options); } Target target = new SentryTarget( options, HubAccessor, SdkDisposeHandle, Clock) { Name = "sentry", Dsn = ValidDsnWithoutSecret, }; if (asyncTarget) { target = new AsyncTargetWrapper(target) { Name = "sentry_async" }; } return(target); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = "https://[email protected]/11"; } else { dsn = RuntimeInfo.IsProduction ? "https://[email protected]/9" : "https://[email protected]/10"; } var target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Debug, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); // Events logged to Sentry go only to Sentry. var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, target) { Final = true }; LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = RuntimeInfo.IsProduction ? "https://*****:*****@sentry.sonarr.tv/11" : "https://*****:*****@sentry.sonarr.tv/9"; } else { dsn = RuntimeInfo.IsProduction ? "https://*****:*****@sentry.sonarr.tv/8" : "https://*****:*****@sentry.sonarr.tv/10"; } var target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Error, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = "https://[email protected]/5"; } else { dsn = RuntimeInfo.IsProduction ? "https://[email protected]/3" : "https://[email protected]/4"; } var target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Debug, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); // Events logged to Sentry go only to Sentry. var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, target) { Final = true }; LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); }
/// <summary> /// Adds a target for Sentry to the NLog configuration. /// </summary> /// <param name="configuration">The NLog configuration.</param> /// <param name="dsn"> The sentry DSN.</param> /// <param name="targetName"> The name to give the new target.</param> /// <param name="optionsConfig">An optional action for configuring the Sentry target options.</param> /// <returns>The configuration.</returns> public static LoggingConfiguration AddSentry(this LoggingConfiguration configuration, string?dsn, string targetName, Action <SentryNLogOptions>?optionsConfig = null) { // Not to throw on code that ignores nullability warnings. // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (configuration is null) { return(configuration !); } var options = new SentryNLogOptions(); optionsConfig?.Invoke(options); Target.Register <SentryTarget>("Sentry"); var target = new SentryTarget(options) { Name = targetName, Layout = "${message}", }; if (dsn != null && string.IsNullOrWhiteSpace(options.Dsn)) { options.Dsn = dsn; } configuration.AddTarget(targetName, target); configuration.AddRuleForAllLevels(targetName); return(configuration); }
public void GetTagsFromProperties_PropertiesMapped() { var logEvent = new LogEventInfo(); logEvent.Properties["a"] = "b"; var actual = Assert.Single(SentryTarget.GetTagsFromProperties(logEvent)); Assert.Equal("a", actual.Key); Assert.Equal("b", actual.Value); }
public async Task UpdateAllPackages(InstallInteractivityLevel interactivityLevel) { if (!_envInfo.IsAdministrator) { Console.WriteLine(); _logger.Warn("Running as administrator is recommended to allow uninterrupted batch updates."); Console.WriteLine(); } var updates = await GetUpdates(); var toInstall = updates.Where(c => c.Status == UpdateStatus.Available).ToList(); var updated = 0; var failed = 0; var restartRequired = false; for (var index = 0; index < toInstall.Count; index++) { var update = toInstall[index]; SentryTarget.AddTag("packageid", update.PackageId); try { _logger.Info("Installing update {0} of {1}", index + 1, toInstall.Count); Console.WriteLine(); await UpdatePackage(update.PackageId, PackageManifest.LATEST_TAG, interactivityLevel); updated++; } catch (InstallerException e) when(e.ExitReason?.Category == ExitCodeTypes.RestartRequired) { restartRequired = true; } catch (Exception e) { _logger.Fatal(e, "An error occurred while updating {0}", update.PackageId); failed++; } finally { SentryTarget.AddTag("packageid", null); } } Console.WriteLine(); _logger.Info("Updates Applied Successfully: {0:n0} Updates failed to apply: {1:n0}", updated, failed); if (restartRequired) { _logger.Warn("One or more installers have requested a system restart to complete the installation."); } }
public void TestPublicConstructor() { Assert.DoesNotThrow(() => new SentryTarget()); Assert.Throws <NLogConfigurationException>(() => { var sentryTarget = new SentryTarget(); var configuration = new LoggingConfiguration(); configuration.AddTarget("NLogSentry", sentryTarget); configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, sentryTarget)); LogManager.Configuration = configuration; }); }
public void TestPublicConstructor() { // ReSharper disable ObjectCreationAsStatement Assert.DoesNotThrow(() => new SentryTarget()); // ReSharper restore ObjectCreationAsStatement Assert.Throws <NLogConfigurationException>(() => { var sentryTarget = new SentryTarget(); var configuration = new LoggingConfiguration(); configuration.AddTarget("NLogSentry", sentryTarget); configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, sentryTarget)); LogManager.Configuration = configuration; }); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = RuntimeInfo.IsProduction ? "https://[email protected]/11" : "https://[email protected]/9"; } else { dsn = RuntimeInfo.IsProduction ? "https://[email protected]/8" : "https://[email protected]/10"; } Target target; try { target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; } catch (Exception ex) { Console.WriteLine("Failed to load dependency, may need an OS update: " + ex.ToString()); LogManager.GetLogger(nameof(NzbDroneLogger)).Debug(ex, "Failed to load dependency, may need an OS update"); // We still need the logging rules, so use a null target. target = new NullTarget(); } var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Warn, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); // Events logged to Sentry go only to Sentry. var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, target) { Final = true }; LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); }
public void TestLoggingToSentry_SendLogEventInfoPropertiesAsTags() { var sentryClient = new Mock <IRavenClient>(); ErrorLevel lErrorLevel = ErrorLevel.Debug; IDictionary <string, string> lTags = null; Exception lException = null; sentryClient .Setup(x => x.Capture(It.IsAny <SentryEvent>())) .Callback((SentryEvent sentryEvent) => { lException = sentryEvent.Exception; lErrorLevel = sentryEvent.Level; lTags = sentryEvent.Tags; }) .Returns("Done"); // Setup NLog var sentryTarget = new SentryTarget(sentryClient.Object) { Dsn = "http://*****:*****@test/4", SendLogEventInfoPropertiesAsTags = true, }; var configuration = new LoggingConfiguration(); configuration.AddTarget("NLogSentry", sentryTarget); configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, sentryTarget)); LogManager.Configuration = configuration; var tag1Value = "abcde"; try { throw new Exception("Oh No!"); } catch (Exception e) { var logger = LogManager.GetCurrentClassLogger(); var logEventInfo = LogEventInfo.Create(LogLevel.Error, "default", e, CultureInfo.InvariantCulture, "Error Message"); logEventInfo.Properties.Add("tag1", tag1Value); logger.Log(logEventInfo); } Assert.IsNotNull(lException); Assert.IsTrue(lException.Message == "Oh No!"); Assert.IsTrue(lTags != null); Assert.IsTrue(lErrorLevel == ErrorLevel.Error); }
public void TestLoggingToSentry() { var sentryClient = new Mock <IRavenClient>(); ErrorLevel lErrorLevel = ErrorLevel.Debug; IDictionary <string, string> lTags = null; Exception lException = null; string lMessage = null; sentryClient .Setup(x => x.Capture(It.IsAny <SentryEvent>())) .Callback((SentryEvent sentryEvent) => { lException = sentryEvent.Exception; lErrorLevel = sentryEvent.Level; lTags = sentryEvent.Tags; lMessage = sentryEvent.Message; }) .Returns("Done"); // Setup NLog var sentryTarget = new SentryTarget(sentryClient.Object) { Dsn = "http://*****:*****@test/4", Layout = "${message}" }; 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.Error(e, "Error Message"); } Assert.IsNotNull(lException); Assert.IsTrue(lException.Message == "Oh No!"); Assert.IsTrue(lMessage == "Error Message"); Assert.IsNotNull(lTags); Assert.IsTrue(0 == lTags.Count); Assert.IsTrue(lErrorLevel == ErrorLevel.Error); }
public void TestInitialization() { var sentryTarget = new SentryTarget { Dsn = "http://*****:*****@test/4", Environment = "Test", Timeout = "00:00:10", }; var logEventInfo = LogEventInfo.CreateNullEvent(); Assert.AreEqual("http://*****:*****@test/4", sentryTarget.Dsn.Render(logEventInfo)); Assert.AreEqual("Test", sentryTarget.Environment.Render(logEventInfo)); Assert.AreEqual("00:00:10", sentryTarget.Timeout); }
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); }
public void TestLoggingToSentry() { var sentryClient = new Mock <IRavenClient>(); ErrorLevel lErrorLevel = ErrorLevel.Debug; IDictionary <string, string> lTags = null; Exception lException = null; sentryClient .Setup(x => x.CaptureException(It.IsAny <Exception>(), It.IsAny <SentryMessage>(), It.IsAny <ErrorLevel>(), It.IsAny <IDictionary <string, string> >(), It.IsAny <object>())) .Callback((Exception exception, SentryMessage msg, ErrorLevel lvl, IDictionary <string, string> d, object extra) => { lException = exception; lErrorLevel = lvl; lTags = d; }) .Returns("Done"); // Setup NLog var sentryTarget = new SentryTarget(sentryClient.Object) { Dsn = "http://*****:*****@test/4", }; 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 == ErrorLevel.Error); }
public Target GetTarget(bool asyncTarget = false) { Target target = new SentryTarget( Options, HubAccessor, SdkDisposeHandle, Clock) { Name = "sentry", Dsn = Options.Dsn ?? Options.DsnLayout, }; if (asyncTarget) { target = new AsyncTargetWrapper(target) { Name = "sentry_async" }; } return(target); }
public SentryTarget GetTarget(Action <SentryNLogOptions> customConfig = null) { var options = Options; if (customConfig != null) { options = new SentryNLogOptions(); customConfig(options); } var target = new SentryTarget( options, HubAccessor, SdkDisposeHandle, Clock) { Dsn = ValidDsnWithoutSecret, }; return(target); }
private static void RegisterSentry(bool updateClient) { string dsn; if (updateClient) { dsn = RuntimeInfo.IsProduction ? "https://*****:*****@sentry.sonarr.tv/11" : "https://*****:*****@sentry.sonarr.tv/9"; } else { dsn = RuntimeInfo.IsProduction ? "https://*****:*****@sentry.sonarr.tv/8" : "https://*****:*****@sentry.sonarr.tv/10"; } var target = new SentryTarget(dsn) { Name = "sentryTarget", Layout = "${message}" }; var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Warn, target); LogManager.Configuration.AddTarget("sentryTarget", target); LogManager.Configuration.LoggingRules.Add(loggingRule); // Events logged to Sentry go only to Sentry. var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, target) { Final = true }; LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); }
public void Setup() { Subject = new SentryTarget("https://[email protected]/111111"); }
public void GetTagsFromProperties_NoProperties() { var logEvent = new LogEventInfo(); Assert.Empty(SentryTarget.GetTagsFromProperties(logEvent)); }