Exemplo n.º 1
0
 public static void Info <T>(
     this ILogger <T> logger,
     Exception exception,
     string message,
     params object[] args
     )
 => logger.LogInformation(exception, message, args);
Exemplo n.º 2
0
 public static void Info <T>(
     this ILogger <T> logger,
     EventId eventId,
     string message,
     params object[] args
     )
 => logger.LogInformation(eventId, message, args);
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()

                         .Enrich.With(new SimpleClassEnricher())
                         .Enrich.FromLogContext()

                                                                                                                                                                           // en dit met die :
                         .WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {MyCustom} {RequestPath} {Message}{Exception} @ {SourceContext:20}{NewLine}") //[{SourceContext}{Properties:j}]

                                                                                                                                                                           //wasdit
                         .WriteTo.Logger(lc => lc
                                                                                                                                                                           // .Filter.ByIncludingOnly(Matching.FromSource("LoggingWeb.Data"))
                                         .WriteTo.File("data-log.txt"))
                         .CreateLogger();

            using (LogContext.PushProperty("MyCustom", "jemoeder"))
            {
                Log.Information("Whutever");
            }

            //   Task<byte[]> readAsync = ReadAsync(new FileInfo(@"C:\Users\Niels\Downloads\adwcleaner_8.0.5.exe"));
            //    readAsync.Wait();

            SerilogLoggerFactory factory = new SerilogLoggerFactory(Log.Logger);
            ILoggerFactory       fck     = factory;
            ILogger <Program>    nother  = fck.CreateLogger <Program>();

            ILogger <Program> logger = factory.CreateLogger <Program>();

            logger.LogInformation("Zo kan het dus ook");

            try
            {
                IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args);
                hostBuilder.ConfigureWebHostDefaults(webHostBuilder =>
                {
                    webHostBuilder.UseStartup <Startup>()
                    .UseSerilog();
                });

                var host = hostBuilder.Build();
                host.Run();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        public void Run(string[] args = null)
        {
            long          id;
            StringContent requestBody = null;

            switch (args.Length)
            {
            case 1:
                Id          = 1001;
                Uri         = apiConfig.uri.Replace("{Id}", Id.ToString());
                FilePath    = args[0];
                requestBody = GetUploadFileRequestBody(FilePath);
                break;

            case 2:
                if (Int64.TryParse(args[0], out id))
                {
                    Id          = id;
                    Uri         = apiConfig.uri.Replace("{Id}", Id.ToString());
                    FilePath    = args[1];
                    requestBody = GetUploadFileRequestBody(FilePath);
                }
                else
                {
                    _logger.LogInformation("Oracle Service Cloud Attachment Upload Error: Integer ID NOT Supplied");
                }
                break;

            case 3:
                if (Int64.TryParse(args[0], out id))
                {
                    Id          = id;
                    Uri         = apiConfig.uri.Replace("{Id}", Id.ToString());
                    MappedId    = args[1];
                    FilePath    = args[2];
                    requestBody = GetUploadFileRequestBody(Id, MappedId, FilePath);
                }
                else
                {
                    _logger.LogInformation("Oracle Service Cloud Attachment Upload Error: Integer ID NOT Supplied");
                }
                break;
            }
            if (requestBody != null)
            {
                _logger.LogInformation($"Start Oracle Service Cloud Attachment Upload: {FilePath} {Uri}");
                OracleServiceCloudAttachmentUpload(requestBody).Wait();
                _logger.LogInformation("End Oracle Service Cloud Attachment Upload");
            }
        }
        public void Run(string[] args = null)
        {
            using (var reader = new StreamReader(args[0]))
            {
                List <Attachment> attachments = new List <Attachment>();
                long Id;
                long contactId;
                long accountId;
                //  long contentTypeId;
                long       entryTypeId;
                Attachment attachmentSave = new Attachment();
                int        lineNo         = 0;
                while (!reader.EndOfStream)
                {
                    var line      = reader.ReadLine();
                    var valuesArr = line.Split('|');
                    var hasline   = false;

                    if (valuesArr.Length > 2)
                    // Array has 2 parameters, which expects to be the incident ID. (Possibly new row and possibly a row that has wrapped.)
                    {
                        if (hasline == true)
                        {
                            attachments.Add(attachmentSave);
                        }
                        else if (hasline == false)
                        {
                            attachmentSave = new Attachment();
                        }

                        Attachment attachment = new Attachment();
                        if (Int64.TryParse(valuesArr[2], out Id))
                        {
                            Int64.TryParse(valuesArr[6], out contactId);
                            Int64.TryParse(valuesArr[7], out entryTypeId);
                            Int64.TryParse(valuesArr[5], out accountId);
                            // If contentTypeId is passed through the datasource leverage this line and set to the appropriate VaulesArr[x]
                            //Int64.TryParse(valuesArr[7], out contentTypeId);
                            attachment.Id       = Id;
                            attachment.bodyText = valuesArr[9].Replace("\\", "\\\\") + "\\n"; // Add line break
                            if (contactId > 0)
                            {
                                attachment.contactId = contactId;
                            }
                            attachment.accountId     = accountId;
                            attachment.contentTypeId = 1; // contentTypeId;
                            attachment.entryTypeId   = entryTypeId;
                            hasline        = true;
                            attachmentSave = attachment;
                        }
                    }
                    else if (valuesArr.Length < 2)
                    {
                        // Found additional body text. Add it to the last file and read the next row.
                        attachmentSave.bodyText = attachmentSave.bodyText + valuesArr[0].Replace("\\", "\\\\") + "\\n"; // Add line break
                    }
                    if (hasline == true)
                    {
                        attachments.Add(attachmentSave);
                    }
                }
                foreach (Attachment att in attachments)
                {
                    ++lineNo; // Row Number
                    // Logging Begins
                    _logger.LogInformation("****Thread Loop and Pass to format JSON ****");
                    _logger.LogInformation($" Line Number: {lineNo}");
                    StringContent requestBody = null;
                    Uri         = apiConfig.uri.Replace("{Id}", att.Id.ToString());                                                         // Endpoint and ID (IncidentId)
                    FilePath    = att.bodyText;                                                                                             // Thread comment details
                    requestBody = GetUploadFileRequestBody(att.bodyText, att.contentTypeId, att.contactId, att.accountId, att.entryTypeId); // Pass contents to format JSON
                    _logger.LogInformation($" Thread Endpoint: {Uri}");
                    _logger.LogInformation($" INCIDENTID: { att.Id.ToString()}");
                    if (requestBody != null)
                    {
                        OracleServiceCloudAttachmentUpload(requestBody).Wait(); // Post to API
                    }
                    else if (requestBody == null)
                    {
                        _logger.LogInformation("RequestBodyNull");
                    }
                }
            }
        }