public async Task <IActionResult> TryExecuteAsync <T>(Func <Task <T> > code) { var result = await _faultlessExecutionService.TryExecuteAsync(code); if (result.WasSuccessful) { return(new OkObjectResult(result.ReturnValue)); } else { _logger.LogError(result.Exception, "Exception caught; BadRequest with FailModel will be sent to client"); return(new BadRequestObjectResult(this.BuildBadRequestObject(result))); } }
public bool CommitHandled() { var errors = new List <Tuple <string, string> >(); try { Commit(); } catch (Exception e) { _logger.LogError(new EventId(370, "EntityFrameWork-Commit"), e, "Error during commit, not rethrowned."); return(false); } return(true); }
public void Run() { if (_working) { _log.LogWarning("Skipping catalog invalidation because previous run has not completed yet"); return; } _working = true; try { DateTimeOffset start = store.LastScanEndDate; DateTimeOffset end = DateTimeOffset.UtcNow; _log.LogInformation("Getting all upstream changes between {0} and {1}", start, end); var changes = reader.GetFlattenedEntries(start, end); bool anyFailed = false; foreach (var h in this.UpdatedEntry.GetInvocationList()) { try { var del = (EventHandler <CatalogEntryEventArgs>)h; del(this, new CatalogEntryEventArgs(changes)); } catch (Exception ex) { anyFailed = true; _log.LogError("Failed to execute catalog entry handler", ex); } } if (!anyFailed) { store.LastScanEndDate = end; } _log.LogInformation("Finished handling {0} upstream changes", changes.Count); } catch (Exception ex) { _log.LogError("Catalog scan failed", ex); } finally { _working = false; } }
public static void StartSubscriber(IWebHost host) { using (var scope = host.Services.CreateScope()) { var provider = scope.ServiceProvider; var subscriptionOptions = provider.GetService <IOptions <SubscriberOptions> >(); Microsoft.Extensions.Logging.ILogger <Program> logger = provider.GetService <Microsoft.Extensions.Logging.ILogger <Program> >(); var readSourceName = subscriptionOptions.Value.TopicName; if (string.IsNullOrWhiteSpace(readSourceName)) { throw new Exception("Event store subcriber cannot be started."); } var repository = provider.GetService <IReadModelRepository <ReadPointer> >(); var readPointer = repository.GetAll() .FirstOrDefault(x => x.SourceName == readSourceName); if (readPointer == null) { readPointer = new ReadPointer { SourceName = readSourceName, Position = -1, CreatedOn = DateTime.Now, LastModifiedOn = DateTime.Now, PublicId = Guid.NewGuid() }; Task.Run(() => { try { repository.AddAsync(readPointer); } catch (Exception e) { logger.LogError(e, e.Message); throw; } }).Wait(); } var eventSubscriber = provider.GetService <IEventStoreSubscriber>(); if (eventSubscriber.IsStarted) { return; } var position = readPointer.Position < 0 ? null : readPointer.Position; eventSubscriber.Start(position); } }
private static INotificationManager CreateNotifier(Microsoft.Extensions.Logging.ILogger <Program> logger, EmailConfig emailConfig, ServiceProvider serviceProvider) { logger.LogInformation("Creating notifier for {0} ...", emailConfig.Domain); INotificationManager notifier; try { notifier = serviceProvider.GetService <INotificationManager>(); } catch (Exception e) { logger.LogError(e, "Cannot create notifier."); throw; } logger.LogInformation("Notifier created."); return(notifier); }
public async Task InvokeAsync(HttpContext context) { try { await _next(context); } catch (System.Exception ex) { _logger.LogError(ex, ex.Message); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; var response = _env.IsDevelopment() ? new ApiException((int)HttpStatusCode.InternalServerError, ex.Message, ex.StackTrace.ToString()) : new ApiException((int)HttpStatusCode.InternalServerError); var options = new System.Text.Json.JsonSerializerOptions { PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase }; var json = System.Text.Json.JsonSerializer.Serialize(response, options); await context.Response.WriteAsync(json); } }
public void LogError(string message, Exception exception) { _logger.LogError(exception, message); }
public async Task Post([FromBody] Update update) { try { if (update.Message.Type == Telegram.Bot.Types.Enums.MessageType.Text) { string answer = update.Message.Text.ToLower(); int v = Configuration.GetValue <int>("JuiceTelegramBotAdminId"); //ToDo: rename switch (answer) { case "/start": case "/hi": case "hi": await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Hi, " + update.Message.Chat.FirstName + "! Choice the beverage you want: \n We have:\n" + string.Join("\n", juiceService.GetJuiceList().Select(juice => "/" + juice))); await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "If you don't see the beverage you want, you can add it by yourself. \n For adding a new beverage just imput the name"); if (update.Message.Chat.Id == v) { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "For manage the order list, please, choose the command: " + "\n /viewebeverageslist to show beverages list" + "\n /viewcustombeverage to show beverages added by users" + "\n /viewnotapproved to show beverages waiting for approving" + "\n For manage the order list, please, choose the command: " + "\n /vieworders to show the order list " + "\n /killthemall to clear the order list"); } break; case "/viewebeverageslist": if (update.Message.Chat.Id == v) { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, string.Join("\n", juiceService.GetJuiceList().Select(item => string.Format("Beverage name: {0}, Is custom {1}, Approved:{2}, Date:{3}, User name:{4}", item.Name, item.IsCustom, item.Approved, item.JuiceDateTime.ToShortDateString(), item.UserName)))); } else { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, string.Join("\n", juiceService.GetJuiceList().Select(juice => "/" + juice.Name))); } break; case "/viewcustombeverage": if (update.Message.Chat.Id == v) { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Custom beverages: \n" + string.Join("\n", juiceService.GetJuiceList().Where(j => j.IsCustom == true).Select(item => item.Name))); } else { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Sorry, " + update.Message.Chat.FirstName + ", but you haven't permissions for this operation :-("); } break; case "/viewnotapproved": if (update.Message.Chat.Id == v) { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Not approved beverages: \n" + string.Join("\n", juiceService.GetJuiceList().Where(j => j.Approved == false).Select(item => item.Name + $" Approve: /approve_{item.Name}, Delete: /delete_{item.Name}"))); } else { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Sorry, " + update.Message.Chat.FirstName + ", but you haven't permissions for this operation :-("); } break; case "/vieworders": if (update.Message.Chat.Id == v) { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Ordered beverages: \n" + string.Join("\n", orderService.GetOrderList().Select(item => item.Juice.Name + " " + item.OrderDateTime.ToShortDateString()))); } else { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Sorry, " + update.Message.Chat.FirstName + ", but you haven't permissions for this operation :-("); } break; case "/killthemall": if (update.Message.Chat.Id == v) { orderService.ClearList(); await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "All orders are cleared!"); } else { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Sorry, " + update.Message.Chat.FirstName + ", but you haven't permissions for this operation :-("); } break; default: if (juiceService.IsInJuices(answer)) { if (orderService.IsInOrders(answer)) { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, answer + " is already ordered."); } else { orderService.AddOrder(answer, DateTime.Now); await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Thank you for your order!"); } } else { juiceService.AddJuice(answer, true, false, DateTime.Now, update.Message.Chat.FirstName); orderService.AddOrder(answer, DateTime.Now); await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Thank you for your order!"); } break; } } else { await telegramBot.SendTextMessageAsync(update.Message.Chat.Id, "Sorry, I can understand you. Try to say /Hi"); } } catch (Exception ex) { logger.LogError(ex, "Can't process message"); } }
public void LogError(Exception e, string message, params object[] p) { _logger.LogError(e, message, p); }
public void Exception(string ex) { _logger.LogError(ex); }
public void Error(object message, Exception exception = null) { _logger.LogError(message.ToString()); }