static void Main() { // Example of code-only setup, alteratively this can be in the App.config // rollupSeconds is 0 so a new file is always generated, for demonstration purposes ErrorStore.Setup("Samples.Console", new JSONErrorStore(path: "Errors", rollupSeconds: 0)); // Optional: for logging all unhandled exceptions AppDomain.CurrentDomain.UnhandledException += ExceptionalHandler; DisplayExceptionStats(); PauseForInput(); try { throw new Exception("Just a try/catch test"); } catch (Exception ex) { // logged, but caught so we don't crash ErrorStore.LogExceptionWithoutContext(ex); } DisplayExceptionStats(); PauseForInput(); System.Console.WriteLine("This next one will crash the program, but will be logged on the way out..."); PauseForInput(); // one not explicitly caught, will be logged by ExceptionHandler throw new Exception("I am an exception thrown on exit"); }
static void Main(string[] args) { // init settings new AppSettings().Init(); ErrorStore.Setup(ShareConstants.ExceptionHanlderAppName, new StackExchange.Exceptional.Stores.SQLErrorStore(AppSettings.Base.Connections.SimpleFeedly.ConnectionString)); // setup DatabaseAccess helper new SimpleFeedlyDatabaseAccess().Setup(() => { return(new DatabaseAccessSettings( connectionString: AppSettings.Base.Connections.SimpleFeedly.ConnectionString, timeout: 200 )); }); HostFactory.Run(config => { config.UseNLog(); config.Service <CrawlerService>(s => { s.ConstructUsing(name => new CrawlerService()); s.WhenStarted(service => service.Start()); s.WhenStopped(service => service.Stop()); }); //Setup Account that window service use to run. config.RunAsLocalSystem(); config.SetServiceName("SimpleFeedly.Crawler"); config.SetDisplayName("SimpleFeedly Crawler"); config.SetDescription("SimpleFeedly Crawler"); }); }
private static void InitializeExceptionLog() { ErrorStore.Setup("eLink", new SqlErrorStore(null, "Default")); ErrorStore.GetCustomData = (exception, context, data) => { foreach (var key in exception.Data.Keys) { var s = key as string; if (s != null && s.StartsWith("log:", StringComparison.OrdinalIgnoreCase)) { string v; var value = exception.Data[key]; if (value == null) v = "[null]"; else v = value.ToString(); data.Add(s.Substring(4), v); } } }; ErrorStore.OnBeforeLog += (sender, args) => { if (args.Error.Exception != null && args.Error is INotLoggedException) args.Abort = true; args.Error.Cookies.Remove(FormsAuthentication.FormsCookieName); ReplaceKey(args.Error.Form, "Password"); ReplaceKey(args.Error.Form, "PasswordConfirm"); }; Dependency.Resolve<IDependencyRegistrar>().RegisterInstance<IExceptionLogger>(new ErrorStoreLogger()); }
private static void ConfigExceptionHandling(Config config) { ErrorStore.Setup(config.GetString("service.name"), new JSONErrorStore(config.GetString("service.exceptions-path"), 200)); AppDomain.CurrentDomain.UnhandledException += (sender, e) => { if (isLoggingException) { return; } using (new DelegateDisposable(() => isLoggingException = true, () => isLoggingException = false)) { var ex = e.ExceptionObject as Exception; if (ex != null) { try { ErrorStore.LogExceptionWithoutContext(ex); } catch (Exception) { Log.Fatal(ex); } } } }; AppDomain.CurrentDomain.FirstChanceException += (sender, e) => { if (isLoggingException) { return; } using (new DelegateDisposable(() => isLoggingException = true, () => isLoggingException = false)) { var ex = e.Exception; if (ex != null) { try { ErrorStore.LogExceptionWithoutContext(ex); } catch (Exception) { Log.Info(ex); } } } }; }
private static void Main() { // Example of code-only setup, alternatively this can be in the App.config // rollupSeconds is 0 so a new file is always generated, for demonstration purposes ErrorStore.Setup("Samples.Console", new JSONErrorStore(new ErrorStoreSettings { Path = "Errors", RollupPeriod = null })); // How to do it with no roll-up //ErrorStore.Setup("Samples.Console", new JSONErrorStore(path: "Errors")); // Example of a code-only email setup, alternatively this can be in the App.config EmailNotifier.Setup(new EmailSettings { SMTPHost = "localhost", // Use Papercut here for testing: https://github.com/ChangemakerStudios/Papercut FromAddress = "*****@*****.**", FromDisplayName = "Bob the Builder", ToAddress = "*****@*****.**" }); // Optional: for logging all unhandled exceptions AppDomain.CurrentDomain.UnhandledException += ExceptionalHandler; // Normally we wouldn't want to .GetAwaiter().GetResult(), but async Main is only on a the latest platforms at the moment DisplayExceptionStats().GetAwaiter().GetResult(); PauseForInput(); try { throw new Exception("Just a try/catch test"); } catch (Exception ex) { // logged, but caught so we don't crash ex.LogNoContext(); } DisplayExceptionStats().GetAwaiter().GetResult(); PauseForInput(); WriteLine("This next one will crash the program, but will be logged on the way out..."); PauseForInput(); // one not explicitly caught, will be logged by ExceptionHandler throw new Exception("I am an exception thrown on exit"); }
/// <summary> /// Fires on Application Start /// </summary> protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); MvcHandler.DisableMvcResponseHeader = true; FluentValidationModelValidatorProvider.Configure(provider => { provider.ValidatorFactory = new ViewModelValidatorFactory(); }); // Disable Code First Migrations Database.SetInitializer <BrewgrContext>(null); // Setup Exception Error Store ErrorStore.Setup("Brewgr.com", new SQLErrorStore(ConfigurationManager.ConnectionStrings["Brewgr_ConnectionString"].ConnectionString)); }