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; } }
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); }
private async void RunSportNews() { logger.LogInformation("RunSportNews starts at " + Environment.TickCount); DataContext dataContext = GetDataContext(); logger.LogInformation("dataContext == null ? " + (dataContext == null)); NewsService newsService = new NewsService(dataContext, configuration, logger); if (newsService != null) { NewsAPIModel sport = await newsService.GetHTTPNews(CountriesEnum.Australia.ToString(), Category.Sport.ToString(), DateTime.Now.AddDays(-1), DateTime.Now); if (sport != null) { for (int i = 0; i < sport.articles.Count() - 1; i++) { News news = new News(); news.NewsTitle = sport.articles[i].title; news.NewsURL = sport.articles[i].url; news.NewsSource = sport.articles[i].source.name; news.NewsCategory = Category.Sport.ToString(); news.NewsCountry = CountriesEnum.Australia.ToString(); DateTime tempDate; if (DateTime.TryParse(sport.articles[i].publishedAt, out tempDate)) { news.DatePublished = tempDate; } bool result = await newsService.Create(news); } } } logger.LogInformation("RunSportNews stops at " + Environment.TickCount); }
} // End Task InvokeAsync private async System.Threading.Tasks.Task ProcessAcmeChallenge(Microsoft.AspNetCore.Http.HttpContext context) { string path = context.Request.Path.ToString(); _logger.LogDebug("Challenge invoked: {challengePath} by {IpAddress}", path, context.Connection.RemoteIpAddress); // var allChallenges = await _persistenceService.GetPersistedChallengesAsync(); MatchingChallenge[] allChallenges = new MatchingChallenge[] { new MatchingChallenge() }; MatchingChallenge matchingChallenge = null; if (path.Length > s_lenMagicPrefix) { string requestedToken = path.Substring($"{MagicPrefix}/".Length); for (int i = 0; i < allChallenges.Length; ++i) { if (string.Equals(allChallenges[i].Token, requestedToken, System.StringComparison.Ordinal)) { matchingChallenge = allChallenges[i]; break; } // End if (string.Equals(allChallenges[i].Token, requestedToken, System.StringComparison.Ordinal)) } // Next i } // End if (path.Length > MagicPrefix.Length) if (matchingChallenge == null) { _logger.LogInformation("The given challenge did not match {challengePath} among {allChallenges}", path, allChallenges); context.Response.StatusCode = (int)System.Net.HttpStatusCode.PreconditionFailed; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync( text : "d'OH.", cancellationToken : context.RequestAborted ); await context.Response.CompleteAsync(); return; } // End if (matchingChallenge == null) // token response is always in ASCII so char_count would be equal to byte_count here context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK; context.Response.ContentLength = matchingChallenge.Response.Length; // context.Response.ContentType = "application/octet-stream"; context.Response.ContentType = "text/plain; charset=ascii"; await context.Response.WriteAsync( text : matchingChallenge.Response, cancellationToken : context.RequestAborted); } // End Task ProcessAcmeChallenge
public CommonSampleService( Microsoft.Extensions.Configuration.IConfiguration configuration , Microsoft.Extensions.Logging.ILogger <CommonSampleService> logger , MyConfig config , Microsoft.Extensions.Options.IOptions <SmtpConfig> smtp ) { System.Console.WriteLine(smtp.Value.Server); this.m_configuration = configuration; this.m_logger = logger; System.Console.WriteLine(config.A); System.Console.WriteLine(config.B); logger.LogInformation("Class instatiated"); }
private async void RunForex() { logger.LogInformation("RunForex starts at " + Environment.TickCount); DataContext dataContext = GetDataContext(); logger.LogInformation("dataContext == null ? " + (dataContext == null)); ForexService forexService = new ForexService(dataContext, configuration, logger); if (forexService != null) { ForexModel forexModel = forexService.GetHTTPForex(); if (forexModel != null) { Forex forex = new Models.Forex(forexModel); if (forex != null) { bool result = await forexService.Update(forex); } } } logger.LogInformation("RunForex stops at " + Environment.TickCount); }
private async void RunPreciousMetal() { logger.LogInformation("RunPreciousMetal starts at " + Environment.TickCount); DataContext dataContext = GetDataContext(); logger.LogInformation("dataContext == null ? " + (dataContext == null)); PreciousMetalService service = new PreciousMetalService(dataContext, configuration, logger); if (service != null) { PreciousMetalModel preciousMetalModel = await service.GetHTTPPrices(); if (preciousMetalModel != null) { PreciousMetal metal = new Models.PreciousMetal(preciousMetalModel); if (metal != null) { bool result = await service.Update(metal); } } } logger.LogInformation("RunPreciousMetal stops at " + Environment.TickCount); }
public void Info(string message, params object[] args) { _logger.LogInformation(message, args); }
private async void RunOpenWeather() { logger.LogInformation("Run Weather Service starts at " + Environment.TickCount); DataContext dataContext = GetDataContext(); logger.LogInformation("dataContext == null ? " + (dataContext == null)); WeatherService weatherService = new WeatherService(dataContext, configuration, logger); OpenWeather sydneyWeather = await weatherService.GetHTTPWeather(City.Sydney); if (sydneyWeather != null) { logger.LogInformation("sydneyWeather != null"); await weatherService.Update(sydneyWeather); } else { logger.LogInformation("sydneyWeather == null"); } OpenWeather perthWeather = await weatherService.GetHTTPWeather(City.Perth); if (perthWeather != null) { logger.LogInformation("perthWeather != null"); await weatherService.Update(perthWeather); } else { logger.LogInformation("perthWeather == null"); } OpenWeather melbourneWeather = await weatherService.GetHTTPWeather(City.Melbourne); if (melbourneWeather != null) { logger.LogInformation("melbourneWeather != null"); await weatherService.Update(melbourneWeather); } else { logger.LogInformation("melbourneWeather == null"); } OpenWeather hobartWeather = await weatherService.GetHTTPWeather(City.Hobart); if (hobartWeather != null) { logger.LogInformation("hobartWeather == null"); await weatherService.Update(hobartWeather); } else { logger.LogInformation("hobartWeather != null"); } OpenWeather darwinWeather = await weatherService.GetHTTPWeather(City.Darwin); if (darwinWeather != null) { logger.LogInformation("darwinWeather != null"); await weatherService.Update(darwinWeather); } else { logger.LogInformation("darwinWeather == null"); } OpenWeather canberraWeather = await weatherService.GetHTTPWeather(City.Canberra); if (canberraWeather != null) { logger.LogInformation("canberraWeather != null"); await weatherService.Update(canberraWeather); } else { logger.LogInformation("canberraWeather == null"); } OpenWeather brisbaneWeather = await weatherService.GetHTTPWeather(City.Brisbane); if (brisbaneWeather != null) { logger.LogInformation("brisbaneWeather != null"); await weatherService.Update(brisbaneWeather); } else { logger.LogInformation("brisbaneWeather == null"); } OpenWeather adelaideWeather = await weatherService.GetHTTPWeather(City.Adelaide); if (adelaideWeather != null) { logger.LogInformation("adelaideWeather != null"); await weatherService.Update(adelaideWeather); } else { logger.LogInformation("adelaideWeather == null"); } logger.LogInformation("Run Weather Service stops at " + Environment.TickCount); }
public void LogInfo(string message, params object[] p) { _logger.LogInformation(message, p); }
public void Info(object message, Exception exception = null) { _logger.LogInformation(message.ToString()); }