Skip to content

Commit ca8dc79

Browse files
authored
Merge pull request #809 from cagil-ozdemirag-mw/logger-factory
ILogger factory
2 parents 82684a3 + 6f463c4 commit ca8dc79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+243
-115
lines changed

Source/FikaAmazonAPI.SampleCode/FikaAmazonAPI.SampleCode.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
2828
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
2929
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
30+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
31+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
3032
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3133
<PackageReference Include="RestSharp" Version="112.1.0" />
3234
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="111.2.0" />
35+
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
36+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
3337
<PackageReference Include="System.Collections" Version="4.3.0" />
3438
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
3539
<PackageReference Include="System.Reflection" Version="4.3.0" />
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using FikaAmazonAPI.Parameter.Order;
2+
using FikaAmazonAPI.Utils;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace FikaAmazonAPI.SampleCode;
7+
8+
public class LoggingExamples
9+
{
10+
private AmazonConnection _amazonConnection;
11+
public LoggingExamples(IConfigurationRoot config)
12+
{
13+
var factory = LoggerFactory.Create(builder => builder.AddConsole());
14+
15+
_amazonConnection = new AmazonConnection(new AmazonCredential()
16+
{
17+
//AccessKey = config.GetSection("FikaAmazonAPI:AccessKey").Value,
18+
//SecretKey = config.GetSection("FikaAmazonAPI:SecretKey").Value,
19+
//RoleArn = config.GetSection("FikaAmazonAPI:RoleArn").Value,
20+
ClientId = config.GetSection("FikaAmazonAPI:ClientId").Value,
21+
ClientSecret = config.GetSection("FikaAmazonAPI:ClientSecret").Value,
22+
RefreshToken = config.GetSection("FikaAmazonAPI:RefreshToken").Value,
23+
MarketPlaceID = config.GetSection("FikaAmazonAPI:MarketPlaceID").Value,
24+
SellerID = config.GetSection("FikaAmazonAPI:SellerId").Value,
25+
IsDebugMode = true,
26+
Environment = Constants.Environments.Sandbox
27+
}, loggerFactory: factory);
28+
}
29+
30+
public async Task ConsoleLoggerExample()
31+
{
32+
var listingItemExample = new ListingsItemsSample(_amazonConnection);
33+
await listingItemExample.SetListingsItemAttribute("test");
34+
}
35+
}

Source/FikaAmazonAPI.SampleCode/Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,18 @@ static async Task Main(string[] args)
3737
}));
3838

3939
await Task.WhenAll(tasks);
40+
41+
//var loggingExamples = new SerilogLoggingExamples(config);
42+
//await loggingExamples.ConsoleLoggerExample();
4043

4144
Console.ReadLine();
45+
4246
}
47+
48+
49+
50+
51+
52+
4353
}
4454
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using FikaAmazonAPI.Utils;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Logging;
4+
using Serilog;
5+
6+
namespace FikaAmazonAPI.SampleCode;
7+
8+
public class SerilogLoggingExamples
9+
{
10+
private AmazonConnection _amazonConnection;
11+
12+
public SerilogLoggingExamples(IConfigurationRoot config)
13+
{
14+
Log.Logger = new LoggerConfiguration()
15+
.WriteTo.Console()
16+
.CreateLogger();
17+
var factory = LoggerFactory.Create(c => c.AddSerilog());
18+
19+
_amazonConnection = new AmazonConnection(new AmazonCredential()
20+
{
21+
//AccessKey = config.GetSection("FikaAmazonAPI:AccessKey").Value,
22+
//SecretKey = config.GetSection("FikaAmazonAPI:SecretKey").Value,
23+
//RoleArn = config.GetSection("FikaAmazonAPI:RoleArn").Value,
24+
ClientId = config.GetSection("FikaAmazonAPI:ClientId").Value,
25+
ClientSecret = config.GetSection("FikaAmazonAPI:ClientSecret").Value,
26+
RefreshToken = config.GetSection("FikaAmazonAPI:RefreshToken").Value,
27+
MarketPlaceID = config.GetSection("FikaAmazonAPI:MarketPlaceID").Value,
28+
SellerID = config.GetSection("FikaAmazonAPI:SellerId").Value,
29+
IsDebugMode = true,
30+
Environment = Constants.Environments.Sandbox
31+
}, loggerFactory: factory);
32+
}
33+
34+
public async Task ConsoleLoggerExample()
35+
{
36+
var listingItemExample = new ListingsItemsSample(_amazonConnection);
37+
await listingItemExample.SetListingsItemAttribute("test");
38+
}
39+
}

Source/FikaAmazonAPI/AmazonConnection.cs

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
using System;
55
using System.Globalization;
66
using System.Threading;
7+
using Microsoft.Extensions.Logging;
78

89
namespace FikaAmazonAPI
910
{
1011
public class AmazonConnection
1112
{
13+
private readonly ILoggerFactory _loggerFactory;
1214
private AmazonCredential Credentials { get; set; }
1315

1416
private IRateLimitingHandler RateLimitingHandler { get; }
@@ -93,12 +95,9 @@ public class AmazonConnection
9395
private UnauthorizedAccessException _NoCredentials = new UnauthorizedAccessException($"Error, you cannot make calls to Amazon without credentials!");
9496

9597
public string RefNumber { get; set; }
96-
public AmazonConnection(
97-
AmazonCredential Credentials,
98-
IRateLimitingHandler rateLimitingHandler = null,
99-
string RefNumber = null,
100-
CultureInfo? cultureInfo = null)
98+
public AmazonConnection(AmazonCredential Credentials, IRateLimitingHandler rateLimitingHandler = null, string RefNumber = null, CultureInfo? cultureInfo = null, ILoggerFactory? loggerFactory = null)
10199
{
100+
_loggerFactory = loggerFactory;
102101
this.Authenticate(Credentials);
103102
this.RefNumber = RefNumber;
104103
this.RateLimitingHandler = rateLimitingHandler ?? new RateLimitingHandler();
@@ -119,44 +118,44 @@ private void Init(AmazonCredential Credentials)
119118

120119
this.Credentials = Credentials;
121120

122-
this._Authorization = new AuthorizationService(this.Credentials, this.RateLimitingHandler);
123-
this._AppIntegrationsServiceV20240401 = new AppIntegrationsServiceV20240401(this.Credentials, this.RateLimitingHandler);
124-
this._Orders = new OrderService(this.Credentials, this.RateLimitingHandler);
125-
this._Reports = new ReportService(this.Credentials, this.RateLimitingHandler);
126-
this._Solicitations = new SolicitationService(this.Credentials, this.RateLimitingHandler);
127-
this._Financials = new FinancialService(this.Credentials, this.RateLimitingHandler);
128-
this._CatalogItems = new CatalogItemService(this.Credentials, this.RateLimitingHandler);
129-
this._ProductPricing = new ProductPricingService(this.Credentials, this.RateLimitingHandler);
121+
this._Authorization = new AuthorizationService(this.Credentials, _loggerFactory);
122+
this._AppIntegrationsServiceV20240401 = new AppIntegrationsServiceV20240401(this.Credentials, _loggerFactory);
123+
this._Orders = new OrderService(this.Credentials, _loggerFactory);
124+
this._Reports = new ReportService(this.Credentials, _loggerFactory);
125+
this._Solicitations = new SolicitationService(this.Credentials, _loggerFactory);
126+
this._Financials = new FinancialService(this.Credentials, _loggerFactory);
127+
this._CatalogItems = new CatalogItemService(this.Credentials, _loggerFactory);
128+
this._ProductPricing = new ProductPricingService(this.Credentials, _loggerFactory);
130129

131-
this._FbaInbound = new FbaInboundService(this.Credentials, this.RateLimitingHandler);
132-
this._FbaInventory = new FbaInventoryService(this.Credentials, this.RateLimitingHandler);
133-
this._FbaOutbound = new FbaOutboundService(this.Credentials, this.RateLimitingHandler);
134-
this._FbaSmallandLight = new FbaSmallandLightService(this.Credentials, this.RateLimitingHandler);
135-
this._FbaInboundEligibility = new FbaInboundEligibilityService(this.Credentials, this.RateLimitingHandler);
136-
this._EasyShip20220323 = new EasyShip20220323Service(this.Credentials, this.RateLimitingHandler);
137-
this._AplusContent = new AplusContentService(this.Credentials, this.RateLimitingHandler);
138-
this._Feed = new FeedService(this.Credentials, this.RateLimitingHandler);
139-
this._ListingsItem = new ListingsItemService(this.Credentials, this.RateLimitingHandler);
140-
this._Restrictions = new RestrictionService(this.Credentials, this.RateLimitingHandler);
141-
this._MerchantFulfillment = new MerchantFulfillmentService(this.Credentials, this.RateLimitingHandler);
142-
this._Messaging = new MessagingService(this.Credentials, this.RateLimitingHandler);
143-
this._Notification = new NotificationService(this.Credentials, this.RateLimitingHandler);
144-
this._ProductFee = new ProductFeeService(this.Credentials, this.RateLimitingHandler);
145-
this._ProductType = new ProductTypeService(this.Credentials, this.RateLimitingHandler);
146-
this._Sales = new SalesService(this.Credentials, this.RateLimitingHandler);
147-
this._Seller = new SellerService(this.Credentials, this.RateLimitingHandler);
148-
this._Services = new ServicesService(this.Credentials, this.RateLimitingHandler);
149-
this._ShipmentInvoicing = new ShipmentInvoicingService(this.Credentials, this.RateLimitingHandler);
150-
this._Shipping = new ShippingService(this.Credentials, this.RateLimitingHandler);
151-
this._ShippingV2 = new ShippingServiceV2(this.Credentials, this.RateLimitingHandler);
152-
this._Upload = new UploadService(this.Credentials, this.RateLimitingHandler);
153-
this._Tokens = new TokenService(this.Credentials, this.RateLimitingHandler);
154-
this._FulFillmentInbound = new FulFillmentInboundService(this.Credentials, this.RateLimitingHandler);
155-
this._FulFillmentInboundv20240320 = new FulFillmentInboundServicev20240320(this.Credentials, this.RateLimitingHandler);
156-
this._FulFillmentOutbound = new FulFillmentOutboundService(this.Credentials, this.RateLimitingHandler);
157-
this._VendorDirectFulfillmentOrders = new VendorDirectFulfillmentOrderService(this.Credentials, this.RateLimitingHandler);
158-
this._VendorOrders = new VendorOrderService(this.Credentials, this.RateLimitingHandler);
159-
this._VendorTransactionStatus = new VendorTransactionStatusService(this.Credentials, this.RateLimitingHandler);
130+
this._FbaInbound = new FbaInboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
131+
this._FbaInventory = new FbaInventoryService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
132+
this._FbaOutbound = new FbaOutboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
133+
this._FbaSmallandLight = new FbaSmallandLightService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
134+
this._FbaInboundEligibility = new FbaInboundEligibilityService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
135+
this._EasyShip20220323 = new EasyShip20220323Service(this.Credentials, _loggerFactory, this.RateLimitingHandler);
136+
this._AplusContent = new AplusContentService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
137+
this._Feed = new FeedService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
138+
this._ListingsItem = new ListingsItemService(this.Credentials, _loggerFactory, this.RateLimitingHandler );
139+
this._Restrictions = new RestrictionService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
140+
this._MerchantFulfillment = new MerchantFulfillmentService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
141+
this._Messaging = new MessagingService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
142+
this._Notification = new NotificationService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
143+
this._ProductFee = new ProductFeeService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
144+
this._ProductType = new ProductTypeService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
145+
this._Sales = new SalesService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
146+
this._Seller = new SellerService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
147+
this._Services = new ServicesService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
148+
this._ShipmentInvoicing = new ShipmentInvoicingService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
149+
this._Shipping = new ShippingService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
150+
this._ShippingV2 = new ShippingServiceV2(this.Credentials, _loggerFactory, this.RateLimitingHandler);
151+
this._Upload = new UploadService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
152+
this._Tokens = new TokenService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
153+
this._FulFillmentInbound = new FulFillmentInboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
154+
this._FulFillmentInboundv20240320 = new FulFillmentInboundServicev20240320(this.Credentials, _loggerFactory, this.RateLimitingHandler);
155+
this._FulFillmentOutbound = new FulFillmentOutboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
156+
this._VendorDirectFulfillmentOrders = new VendorDirectFulfillmentOrderService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
157+
this._VendorOrders = new VendorOrderService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
158+
this._VendorTransactionStatus = new VendorTransactionStatusService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
160159

161160
AmazonCredential.DebugMode = this.Credentials.IsDebugMode;
162161
}

Source/FikaAmazonAPI/FikaAmazonAPI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.106" />
3636
<PackageReference Include="AWSSDK.SQS" Version="3.7.301.19" />
3737
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
38+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
3839
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3940
<PackageReference Include="RestSharp" Version="112.1.0" />
4041
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="111.2.0" />

Source/FikaAmazonAPI/Services/AplusContentService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using FikaAmazonAPI.Utils;
2+
using Microsoft.Extensions.Logging;
23

34
namespace FikaAmazonAPI.Services
45
{
56

67
public class AplusContentService : RequestService
78
{
89

9-
public AplusContentService(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
10+
public AplusContentService(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
1011
{
1112

1213
}

Source/FikaAmazonAPI/Services/AppIntegrationsV20240401.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using System.Threading;
8+
using Microsoft.Extensions.Logging;
89

910
namespace FikaAmazonAPI.Services
1011
{
1112
public class AppIntegrationsServiceV20240401: RequestService
1213
{
13-
public AppIntegrationsServiceV20240401(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
14+
public AppIntegrationsServiceV20240401(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
1415
{
1516

1617
}

Source/FikaAmazonAPI/Services/AuthorizationService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
using FikaAmazonAPI.Utils;
55
using System.Threading;
66
using System.Threading.Tasks;
7+
using Microsoft.Extensions.Logging;
78
using static FikaAmazonAPI.AmazonSpApiSDK.Models.Token.CacheTokenData;
89

910
namespace FikaAmazonAPI.Services
1011
{
1112
public class AuthorizationService : RequestService
1213
{
13-
public AuthorizationService(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
14+
public AuthorizationService(AmazonCredential amazonCredential, ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
1415
{
1516
}
1617
public string GetAuthorizationCode(ParameterAuthorizationCode parameterGetOrderMetrics) =>

Source/FikaAmazonAPI/Services/CatalogItemService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
using System.IO;
99
using System.Threading;
1010
using System.Threading.Tasks;
11+
using Microsoft.Extensions.Logging;
1112
using Item = FikaAmazonAPI.AmazonSpApiSDK.Models.CatalogItems.Item;
1213

1314
namespace FikaAmazonAPI.Services
1415
{
1516
public class CatalogItemService : RequestService
1617
{
17-
public CatalogItemService(AmazonCredential amazonCredential, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, rateLimitingHandler)
18+
public CatalogItemService(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
1819
{
1920

2021
}

0 commit comments

Comments
 (0)