Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ILogger factory #809

Merged
merged 12 commits into from
Dec 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="111.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Reflection" Version="4.3.0" />
Expand Down
35 changes: 35 additions & 0 deletions Source/FikaAmazonAPI.SampleCode/LoggingExamples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using FikaAmazonAPI.Parameter.Order;
using FikaAmazonAPI.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI.SampleCode;

public class LoggingExamples
{
private AmazonConnection _amazonConnection;
public LoggingExamples(IConfigurationRoot config)
{
var factory = LoggerFactory.Create(builder => builder.AddConsole());

_amazonConnection = new AmazonConnection(new AmazonCredential()
{
//AccessKey = config.GetSection("FikaAmazonAPI:AccessKey").Value,
//SecretKey = config.GetSection("FikaAmazonAPI:SecretKey").Value,
//RoleArn = config.GetSection("FikaAmazonAPI:RoleArn").Value,
ClientId = config.GetSection("FikaAmazonAPI:ClientId").Value,
ClientSecret = config.GetSection("FikaAmazonAPI:ClientSecret").Value,
RefreshToken = config.GetSection("FikaAmazonAPI:RefreshToken").Value,
MarketPlaceID = config.GetSection("FikaAmazonAPI:MarketPlaceID").Value,
SellerID = config.GetSection("FikaAmazonAPI:SellerId").Value,
IsDebugMode = true,
Environment = Constants.Environments.Sandbox
}, loggerFactory: factory);
}

public async Task ConsoleLoggerExample()
{
var listingItemExample = new ListingsItemsSample(_amazonConnection);
await listingItemExample.SetListingsItemAttribute("test");
}
}
10 changes: 10 additions & 0 deletions Source/FikaAmazonAPI.SampleCode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@ static async Task Main(string[] args)
}));

await Task.WhenAll(tasks);

//var loggingExamples = new SerilogLoggingExamples(config);
//await loggingExamples.ConsoleLoggerExample();

Console.ReadLine();

}






}
}
39 changes: 39 additions & 0 deletions Source/FikaAmazonAPI.SampleCode/SerilogLoggingExamples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using FikaAmazonAPI.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;

namespace FikaAmazonAPI.SampleCode;

public class SerilogLoggingExamples
{
private AmazonConnection _amazonConnection;

public SerilogLoggingExamples(IConfigurationRoot config)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
var factory = LoggerFactory.Create(c => c.AddSerilog());

_amazonConnection = new AmazonConnection(new AmazonCredential()
{
//AccessKey = config.GetSection("FikaAmazonAPI:AccessKey").Value,
//SecretKey = config.GetSection("FikaAmazonAPI:SecretKey").Value,
//RoleArn = config.GetSection("FikaAmazonAPI:RoleArn").Value,
ClientId = config.GetSection("FikaAmazonAPI:ClientId").Value,
ClientSecret = config.GetSection("FikaAmazonAPI:ClientSecret").Value,
RefreshToken = config.GetSection("FikaAmazonAPI:RefreshToken").Value,
MarketPlaceID = config.GetSection("FikaAmazonAPI:MarketPlaceID").Value,
SellerID = config.GetSection("FikaAmazonAPI:SellerId").Value,
IsDebugMode = true,
Environment = Constants.Environments.Sandbox
}, loggerFactory: factory);
}

public async Task ConsoleLoggerExample()
{
var listingItemExample = new ListingsItemsSample(_amazonConnection);
await listingItemExample.SetListingsItemAttribute("test");
}
}
83 changes: 41 additions & 42 deletions Source/FikaAmazonAPI/AmazonConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using System;
using System.Globalization;
using System.Threading;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI
{
public class AmazonConnection
{
private readonly ILoggerFactory _loggerFactory;
private AmazonCredential Credentials { get; set; }

private IRateLimitingHandler RateLimitingHandler { get; }
Expand Down Expand Up @@ -93,12 +95,9 @@
private UnauthorizedAccessException _NoCredentials = new UnauthorizedAccessException($"Error, you cannot make calls to Amazon without credentials!");

public string RefNumber { get; set; }
public AmazonConnection(
AmazonCredential Credentials,
IRateLimitingHandler rateLimitingHandler = null,
string RefNumber = null,
CultureInfo? cultureInfo = null)
public AmazonConnection(AmazonCredential Credentials, IRateLimitingHandler rateLimitingHandler = null, string RefNumber = null, CultureInfo? cultureInfo = null, ILoggerFactory? loggerFactory = null)

Check warning on line 98 in Source/FikaAmazonAPI/AmazonConnection.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 98 in Source/FikaAmazonAPI/AmazonConnection.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
_loggerFactory = loggerFactory;
this.Authenticate(Credentials);
this.RefNumber = RefNumber;
this.RateLimitingHandler = rateLimitingHandler ?? new RateLimitingHandler();
Expand All @@ -119,44 +118,44 @@

this.Credentials = Credentials;

this._Authorization = new AuthorizationService(this.Credentials, this.RateLimitingHandler);
this._AppIntegrationsServiceV20240401 = new AppIntegrationsServiceV20240401(this.Credentials, this.RateLimitingHandler);
this._Orders = new OrderService(this.Credentials, this.RateLimitingHandler);
this._Reports = new ReportService(this.Credentials, this.RateLimitingHandler);
this._Solicitations = new SolicitationService(this.Credentials, this.RateLimitingHandler);
this._Financials = new FinancialService(this.Credentials, this.RateLimitingHandler);
this._CatalogItems = new CatalogItemService(this.Credentials, this.RateLimitingHandler);
this._ProductPricing = new ProductPricingService(this.Credentials, this.RateLimitingHandler);
this._Authorization = new AuthorizationService(this.Credentials, _loggerFactory);
this._AppIntegrationsServiceV20240401 = new AppIntegrationsServiceV20240401(this.Credentials, _loggerFactory);
this._Orders = new OrderService(this.Credentials, _loggerFactory);
this._Reports = new ReportService(this.Credentials, _loggerFactory);
this._Solicitations = new SolicitationService(this.Credentials, _loggerFactory);
this._Financials = new FinancialService(this.Credentials, _loggerFactory);
this._CatalogItems = new CatalogItemService(this.Credentials, _loggerFactory);
this._ProductPricing = new ProductPricingService(this.Credentials, _loggerFactory);

this._FbaInbound = new FbaInboundService(this.Credentials, this.RateLimitingHandler);
this._FbaInventory = new FbaInventoryService(this.Credentials, this.RateLimitingHandler);
this._FbaOutbound = new FbaOutboundService(this.Credentials, this.RateLimitingHandler);
this._FbaSmallandLight = new FbaSmallandLightService(this.Credentials, this.RateLimitingHandler);
this._FbaInboundEligibility = new FbaInboundEligibilityService(this.Credentials, this.RateLimitingHandler);
this._EasyShip20220323 = new EasyShip20220323Service(this.Credentials, this.RateLimitingHandler);
this._AplusContent = new AplusContentService(this.Credentials, this.RateLimitingHandler);
this._Feed = new FeedService(this.Credentials, this.RateLimitingHandler);
this._ListingsItem = new ListingsItemService(this.Credentials, this.RateLimitingHandler);
this._Restrictions = new RestrictionService(this.Credentials, this.RateLimitingHandler);
this._MerchantFulfillment = new MerchantFulfillmentService(this.Credentials, this.RateLimitingHandler);
this._Messaging = new MessagingService(this.Credentials, this.RateLimitingHandler);
this._Notification = new NotificationService(this.Credentials, this.RateLimitingHandler);
this._ProductFee = new ProductFeeService(this.Credentials, this.RateLimitingHandler);
this._ProductType = new ProductTypeService(this.Credentials, this.RateLimitingHandler);
this._Sales = new SalesService(this.Credentials, this.RateLimitingHandler);
this._Seller = new SellerService(this.Credentials, this.RateLimitingHandler);
this._Services = new ServicesService(this.Credentials, this.RateLimitingHandler);
this._ShipmentInvoicing = new ShipmentInvoicingService(this.Credentials, this.RateLimitingHandler);
this._Shipping = new ShippingService(this.Credentials, this.RateLimitingHandler);
this._ShippingV2 = new ShippingServiceV2(this.Credentials, this.RateLimitingHandler);
this._Upload = new UploadService(this.Credentials, this.RateLimitingHandler);
this._Tokens = new TokenService(this.Credentials, this.RateLimitingHandler);
this._FulFillmentInbound = new FulFillmentInboundService(this.Credentials, this.RateLimitingHandler);
this._FulFillmentInboundv20240320 = new FulFillmentInboundServicev20240320(this.Credentials, this.RateLimitingHandler);
this._FulFillmentOutbound = new FulFillmentOutboundService(this.Credentials, this.RateLimitingHandler);
this._VendorDirectFulfillmentOrders = new VendorDirectFulfillmentOrderService(this.Credentials, this.RateLimitingHandler);
this._VendorOrders = new VendorOrderService(this.Credentials, this.RateLimitingHandler);
this._VendorTransactionStatus = new VendorTransactionStatusService(this.Credentials, this.RateLimitingHandler);
this._FbaInbound = new FbaInboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FbaInventory = new FbaInventoryService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FbaOutbound = new FbaOutboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FbaSmallandLight = new FbaSmallandLightService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FbaInboundEligibility = new FbaInboundEligibilityService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._EasyShip20220323 = new EasyShip20220323Service(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._AplusContent = new AplusContentService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Feed = new FeedService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ListingsItem = new ListingsItemService(this.Credentials, _loggerFactory, this.RateLimitingHandler );
this._Restrictions = new RestrictionService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._MerchantFulfillment = new MerchantFulfillmentService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Messaging = new MessagingService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Notification = new NotificationService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ProductFee = new ProductFeeService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ProductType = new ProductTypeService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Sales = new SalesService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Seller = new SellerService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Services = new ServicesService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ShipmentInvoicing = new ShipmentInvoicingService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Shipping = new ShippingService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ShippingV2 = new ShippingServiceV2(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Upload = new UploadService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Tokens = new TokenService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FulFillmentInbound = new FulFillmentInboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FulFillmentInboundv20240320 = new FulFillmentInboundServicev20240320(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FulFillmentOutbound = new FulFillmentOutboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._VendorDirectFulfillmentOrders = new VendorDirectFulfillmentOrderService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._VendorOrders = new VendorOrderService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._VendorTransactionStatus = new VendorTransactionStatusService(this.Credentials, _loggerFactory, this.RateLimitingHandler);

AmazonCredential.DebugMode = this.Credentials.IsDebugMode;
}
Expand Down
1 change: 1 addition & 0 deletions Source/FikaAmazonAPI/FikaAmazonAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.106" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.301.19" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="111.2.0" />
Expand Down
3 changes: 2 additions & 1 deletion Source/FikaAmazonAPI/Services/AplusContentService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using FikaAmazonAPI.Utils;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI.Services
{

public class AplusContentService : RequestService
{

public AplusContentService(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
public AplusContentService(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)

Check warning on line 10 in Source/FikaAmazonAPI/Services/AplusContentService.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{

}
Expand Down
3 changes: 2 additions & 1 deletion Source/FikaAmazonAPI/Services/AppIntegrationsV20240401.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI.Services
{
public class AppIntegrationsServiceV20240401: RequestService
{
public AppIntegrationsServiceV20240401(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
public AppIntegrationsServiceV20240401(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)

Check warning on line 14 in Source/FikaAmazonAPI/Services/AppIntegrationsV20240401.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{

}
Expand Down
3 changes: 2 additions & 1 deletion Source/FikaAmazonAPI/Services/AuthorizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
using FikaAmazonAPI.Utils;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using static FikaAmazonAPI.AmazonSpApiSDK.Models.Token.CacheTokenData;

namespace FikaAmazonAPI.Services
{
public class AuthorizationService : RequestService
{
public AuthorizationService(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
public AuthorizationService(AmazonCredential amazonCredential, ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)

Check warning on line 14 in Source/FikaAmazonAPI/Services/AuthorizationService.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
}
public string GetAuthorizationCode(ParameterAuthorizationCode parameterGetOrderMetrics) =>
Expand Down
3 changes: 2 additions & 1 deletion Source/FikaAmazonAPI/Services/CatalogItemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Item = FikaAmazonAPI.AmazonSpApiSDK.Models.CatalogItems.Item;

namespace FikaAmazonAPI.Services
{
public class CatalogItemService : RequestService
{
public CatalogItemService(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
public CatalogItemService(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
{

}
Expand Down
3 changes: 2 additions & 1 deletion Source/FikaAmazonAPI/Services/EasyShip20220323Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using FikaAmazonAPI.Utils;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI.Services
{
public class EasyShip20220323Service : RequestService
{
public EasyShip20220323Service(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
public EasyShip20220323Service(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using FikaAmazonAPI.Utils;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI.Services
{
public class FbaInboundEligibilityService : RequestService
{
public FbaInboundEligibilityService(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
public FbaInboundEligibilityService(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
{

}
Expand Down
3 changes: 2 additions & 1 deletion Source/FikaAmazonAPI/Services/FbaInboundService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using FikaAmazonAPI.Utils;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI.Services
{
public class FbaInboundService : RequestService
{
public FbaInboundService(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
public FbaInboundService(AmazonCredential amazonCredential, ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
{

}
Expand Down
3 changes: 2 additions & 1 deletion Source/FikaAmazonAPI/Services/FbaInventoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI.Services
{
public class FbaInventoryService : RequestService
{

public FbaInventoryService(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
public FbaInventoryService(AmazonCredential amazonCredential, ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
{

}
Expand Down
Loading
Loading