private async Task OracleServiceCloudAttachmentUpload(StringContent content) { string userName = apiConfig.username, password = apiConfig.password; var credentials = new NetworkCredential(userName, password); // Create HTTP Handler with Credentials using (var handler = new HttpClientHandler { Credentials = credentials }) using (var client = new HttpClient(handler)) { // string json = null; try { // Invoke Oracle Service Cloud Thread Upload Web API _logger.LogInformation($@"-----------------------TRY PROCESS JSON ----------------------"); _logger.LogInformation($@" Access Oracle Service Cloud Thread Web API {Environment.NewLine}uri: {Uri} {Environment.NewLine}UserName: {userName} "); var stringTask = client.PatchAsync(Uri, content).Result; _logger.LogInformation($@" Content: {content.ToString()}"); _logger.LogInformation($@" Header Length: {content.Headers.ContentLength}"); _logger.LogInformation($@" StatusCode: {stringTask.StatusCode}"); _logger.LogInformation($@" Reason Phrase: {stringTask.ReasonPhrase}"); _logger.LogInformation($@" Request Msg: {stringTask.RequestMessage}"); } catch (Exception ex) { _logger.LogError($@"-----------------------CATCH EXCEPTION ----------------------"); _logger.LogError($@"JSON: {content}"); _logger.LogError($@"Exception Result: {ex.HResult}"); _logger.LogError($@"Exception Message: {ex.Message}"); _logger.LogError($@" Credentials {Environment.NewLine}uri: {Uri} {Environment.NewLine}UserName: {userName} "); } _logger.LogInformation($@"---------------------- END THREAD -------------------"); } }
private async Task OracleServiceCloudAttachmentUpload(StringContent content) { string userName = apiConfig.username, password = apiConfig.password; var credentials = new NetworkCredential(userName, password); // Create HTTP Handler with Credentials using (var handler = new HttpClientHandler { Credentials = credentials }) using (var client = new HttpClient(handler)) { string json = null; try { // Invoke Oracle Service Cloud Attachment Upload Web API _logger.LogInformation($@"Access Oracle Service Cloud Attachment Upload Web API {Environment.NewLine}uri: {Uri} {Environment.NewLine}UserName: {userName} PassWord: {password}"); var stringTask = client.PostAsync(Uri, content).Result; _logger.LogInformation($@"Number of bytes processed by Oracle Service Cloud Attachment Upload Web API: {content.Headers.ContentLength}"); } catch (Exception ex) { _logger.LogError(ex.HResult, ex.Message + $@"{Environment.NewLine}uri: {Uri} {Environment.NewLine}UserName: {userName} PassWord: {password}"); } } }
/// <summary> /// Invokes the Request Logger Middleware. /// </summary> /// <param name="httpContext">The HTTP context.</param> /// <returns>Task.</returns> /// <exception cref="ArgumentNullException">httpContext</exception> public async Task Invoke(HttpContext httpContext) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } using (await Timer.SetCurrentTimerAsync(httpContext.Request.Path.Value)) { try { await this._next(httpContext); var statusCode = httpContext.Response?.StatusCode; var level = statusCode > 499 ? LogEventLevel.Error : LogEventLevel.Information; LogForContext(httpContext).Write(level, MessageTemplate); } catch (Exception ex) { foreach (var message in ErrorContext.Current.GetMessages()) { _logger.LogError(message); } LogForContext(httpContext).Error(ex, MessageTemplate); } } }
public static void Error <T>( this ILogger <T> logger, Exception exception, string message, params object[] args ) => logger.LogError(exception, message, args);
public static void Error <T>( this ILogger <T> logger, EventId eventId, string message, params object[] args ) => logger.LogError(eventId, message, args);
public async Task <string> Run() { try { var currencies = JsonSerializer.Deserialize <List <InvestmentTool> >(Environment.GetEnvironmentVariable("currencies"), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); var url = Environment.GetEnvironmentVariable("url"); if (currencies == null || currencies.Count <= 0 || string.IsNullOrEmpty(url)) { return("OK"); } foreach (var currency in currencies) { _logger.LogInformation($"Getting prices from provider for {currency.Code}..."); var currentPrice = await _pgpPriceProvider.GetCurrentPrice(currency.Code, url); currentPrice.InvestmentTool = currency; _logger.LogInformation($"Publishing integration event{nameof(ForeignCurrencyPriceChangedIntegrationEvent)}..."); var foreignPriceChangedIntegrationEvent = new ForeignCurrencyPriceChangedIntegrationEvent(currentPrice.Id, currentPrice.PriceDate, currentPrice.Hour, currentPrice.Minute, currentPrice.CurrencyCode, currentPrice.SalesPrice, currentPrice.BuyingPrice, currentPrice.OpeningPrice, currentPrice.ClosingPrice, currentPrice.HighestPrice, currentPrice.LowestPrice); _eventBus.Publish(foreignPriceChangedIntegrationEvent); _logger.LogInformation("Saving price to DynamoDb..."); _repository.SavePriceAsync(currentPrice).GetAwaiter(); } return("OK"); } catch (Exception e) { _logger.LogError("Unexpected exception." + e.Message); throw; } }