public async Task TestAsync() { var store = GetStore(); Exceptional.Configure(new TestSettings(store)); Assert.True(await store.TestAsync().ConfigureAwait(false)); }
private static void Main() { // Example of code-only setup, alternatively this can be in the App.config // RollupPeriod is null so a new file is always generated, for demonstration purposes Exceptional.Configure(settings => { settings.DefaultStore = new JSONErrorStore(new ErrorStoreSettings { ApplicationName = "Samples.Console", Path = "Errors", RollupPeriod = null }); // Example of a code-only email setup, alternatively this can be in the App.config settings.Register(new EmailNotifier(new EmailSettings { SMTPHost = "localhost", // Use Papercut here for testing: https://github.com/ChangemakerStudios/Papercut FromAddress = "*****@*****.**", FromDisplayName = "Bob the Builder", ToAddress = "*****@*****.**" })); }); // How to do it with normal roll-up //Exceptional.Configure(new ExceptionalSettings() { DefaultStore = new JSONErrorStore("Errors") }); // Optional: for logging all unhandled exceptions Exceptional.ObserveAppDomainUnhandledExceptions(); // 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) { ex.AddLogData("Example string", DateTime.UtcNow.ToString()) .AddLogData("User Id", "You could fetch a user/account Id here, etc.") .AddLogData("Links get linkified", "https://www.google.com"); // 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"); }
private static async Task Main() { // Example of setting things up from appsettings.json config var config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); var exceptionalSettings = config.GetSection("Exceptional").Get <ExceptionalSettings>(); Exceptional.Configure(exceptionalSettings); // Example of code-only setup, alternatively this can be in the appsettings.json (or any config format) as shown above // RollupPeriod is null so a new file is always generated, for demonstration purposes //Exceptional.Configure(settings => //{ // settings.DefaultStore = new JSONErrorStore(new ErrorStoreSettings // { // ApplicationName = "Samples.ConsoleNetCore", // Path = "Errors", // RollupPeriod = null // }); //}); // How to do it with normal roll-up //Exceptional.Configure(new ExceptionalSettings() { DefaultStore = new JSONErrorStore("Errors") }); // Optional: for logging all unhandled exceptions Exceptional.ObserveAppDomainUnhandledExceptions(); await DisplayExceptionStatsAsync(); PauseForInput(); try { throw new Exception("Just a try/catch test"); } catch (Exception ex) { ex.AddLogData("Example string", DateTime.UtcNow.ToString()) .AddLogData("User Id", "You could fetch a user/account Id here, etc.") .AddLogData("Links get linkified", "https://www.google.com"); // logged, but caught so we don't crash ex.LogNoContext(); } await DisplayExceptionStatsAsync(); 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"); }
public static IWebHostBuilder UseYouDoLogging(this IWebHostBuilder builder) { return(builder.ConfigureLogging((context, loggerBuilder) => { loggerBuilder.ClearProviders(); Exceptional.Configure(settings => { settings.AppendFullStackTraces = true; settings.DefaultStore = new SQLErrorStore(context.Configuration["Exceptional"], EntryAssemblyName); }); var logger = GetLogger(EntryAssemblyName); loggerBuilder.AddSerilog(logger); })); }
public void AppNameViaConfigure() { if (TestConfig.Current.SQLServerConnectionString.IsNullOrEmpty()) { Skip.Inconclusive("SQLConnectionString config is missing, unable to test."); } const string appName = "AppNameViaConfig"; Exceptional.Configure(settings => settings.DefaultStore = new SQLErrorStore(TestConfig.Current.SQLServerConnectionString, appName)); Assert.Equal(Exceptional.Settings.DefaultStore.ApplicationName, appName); Assert.Equal(Statics.Settings.DefaultStore.ApplicationName, appName); var error = new Exception().GetErrorIfNotIgnored(Statics.Settings); Assert.Equal(appName, error.ApplicationName); }
private static IServiceCollection AddLuccaLogs(this IServiceCollection services, Action <LuccaLoggerOptions> configureOptions, string appName, ErrorStore errorStore = null) { if (string.IsNullOrWhiteSpace(appName)) { throw new ArgumentNullException(nameof(appName)); } services.AddOptions(); if (configureOptions != null) { services.Configure <LuccaLoggerOptions>(o => { o.ExplicitErrorStore = errorStore; configureOptions(o); }); } if (errorStore != null) { #if NETCOREAPP3_1 services.AddExceptional(o => { o.Store.Type = errorStore.GetType().ToString(); o.DefaultStore = errorStore; }); #else Exceptional.Configure(o => { o.Store.Type = errorStore.GetType().ToString(); o.DefaultStore = errorStore; }); #endif } services.PostConfigure <LuccaLoggerOptions>(o => { if (string.IsNullOrWhiteSpace(o.ApplicationName)) { o.ApplicationName = appName; } }); services.RegisterLuccaLogsProvider(); return(services); }
protected void Application_Start() { // Instead of any web.config entries, you can perform setup entirely through code // Setup Exceptional: // Memory example: //Exceptional.Configure(settings => settings.DefaultStore = new MemoryErrorStore()); // JSON example //Exceptional.Configure(settings => settings.DefaultStore = new JSONErrorStore(path: "~/Errors")); // SQL Example //Exceptional.Configure(settings => settings.DefaultStore = new SQLErrorStore(applicationName: "My Error Log Name", connectionString: "Data Source=.;Initial Catalog=Exceptions;Integrated Security=SSPI;")); Exceptional.Configure(settings => { // Optionally add custom data to any logged exception (visible on the exception detail page): settings.GetCustomData = (exception, data) => { // exception is the exception thrown // data is a Dictionary<string, string> to add custom data too data.Add("Example string", DateTime.UtcNow.ToString()); data.Add("User Id", "You could fetch a user/account Id here, etc."); data.Add("Links get linkified", "https://www.google.com"); }; // Example of how to log command data for anything you want // These display the command and the data key/value pairs in the log settings.ExceptionActions.AddHandler <ExceptionalUtils.Test.RedisException>((e, ex) => { var cmd = e.AddCommand(new Command("Redis")); foreach (string k in ex.Data.Keys) { var val = ex.Data[k] as string; if (k == "redis-command") { cmd.CommandString = val; } if (k.StartsWith("Redis-")) { cmd.AddData(k.Substring("Redis-".Length), val); } } }); settings.Render.JSIncludes.Add("/Content/errors.js"); settings.OnBeforeLog += (sender, args) => { args.Error.Message += " (suffix from OnBeforeLog handler)"; //args.Abort = true; - you could stop the exception from being logged here }; settings.OnAfterLog += (sender, args) => { Trace.WriteLine("The logged exception GUID was: " + args.Error.GUID.ToString()); // optionally var e = args.GetError() to fetch the actual error from the store }; }); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
public void Configure(Action <ExceptionalSettingsBase> configSettings) { Exceptional.Configure(configSettings); }