public async Task <IActionResult> Error() { // Get the details of the exception that occurred IExceptionHandlerPathFeature exceptionFeature = HttpContext.Features.Get <IExceptionHandlerPathFeature>(); if (exceptionFeature != null) { string currentUser = (User == null) ? "Unknown" : User.Identity.Name; string route = string.Concat(exceptionFeature.Path, Request.QueryString.ToString()); // Log Error and return short ID for support purposes ViewData["shortId"] = await _errorLogger.LogErrorAsync(exceptionFeature.Error, currentUser, route); } return(View("Error")); }
public async Task <bool> SaveImage(IFormFile file, string savePath, bool asThumbnail = false) { if (!FileTypes.FilenameImpliesImage(file.FileName.Trim())) { return(false); } try { using var image = Image.Load(file.OpenReadStream()); if (image == null) { return(false); } if (asThumbnail) { image.Mutate(x => x.AutoOrient() .Resize(new ResizeOptions { Size = new Size(CTS.ThumbnailSize), Mode = ResizeMode.Pad }) .BackgroundColor(Rgba32.White)); } else { image.Mutate(x => x.AutoOrient()); } if (image == null) { return(false); } image.Save(savePath); return(true); } catch (Exception ex) { // Log error but take no other action here ex.Data.Add("Action", "Saving Image"); ex.Data.Add("As Thumbnail", asThumbnail); ex.Data.Add("IFormFile", file); ex.Data.Add("Save Path", savePath); await _errorLogger.LogErrorAsync(ex); return(false); } }
private void ErrorSubscription() { appStore .DistinctUntilChanged(state => new { state.Error }) .Subscribe(state => { if (state.Error != null) { Device.BeginInvokeOnMainThread(() => { errorLogger.LogErrorAsync(state.Error); App.Current.MainPage.DisplayAlert("Ups...", "Unexpected error occured. Information about this error will be sent to our server. We will make as much as we can to repair it!", "Ok"); }); } }); }
public async Task TryDeleteFileAsync(string filePath) { if (string.IsNullOrEmpty(filePath)) { return; } try { File.Delete(filePath); } catch (Exception ex) { // Log error but take no other action here ex.Data.Add("Action", "Deleting File"); ex.Data.Add("File", filePath); await _errorLogger.LogErrorAsync(ex); } }
public static IApplicationBuilder UseLimFxExceptionHandler(this IApplicationBuilder app, IErrorLogger errorLogger) { app.UseExceptionHandler(errorApp => { errorApp.Run(async context => { context.Response.ContentType = "text/html"; var exceptionHandlerPathFeature = context.Features.Get <IExceptionHandlerPathFeature>(); var err = exceptionHandlerPathFeature.Error; await errorLogger.LogErrorAsync(err, context); await StatuscodeSetter(context, err); }); }); return(app); }