Sample Code for Exception based logging with .NET SDK using C# Find the answer to your question
Advanced Search Product -Select Product- Trading API Shopping API Merchandising API Feedback API Finding API Product Services Sandbox Others MIP Media API Notification API Identity API Charity API Taxonomy API Catalog API Recommendation API Compliance API Logistics API Finances API(Alpha) Negotiation API Sell Feed API Marketing Ads API Account API Inventory API Fulfillment API Marketing Promotion API Analytics API Metadata API Offer API Marketplace Insights API Deal API Marketing API Feed API Browse API Order API Analytics API Key Management API Cancellation API Case Management API Inquiry API Return API Category -Select- Getting Started Sample Code Troubleshooting HowTo's / Best Practices No Value
Language -Select- C# Flex Java JavaScript PHP VB.NET VB6
Format -Select- All XML SOAP JSON Name Value N/A
SDK -Select- .NET Java JavaScript Flax/Flash Mobile - iOS None
Sort by Default Summary New Description Date Updated
Sort order Descending Ascending
Search
Published: August 19 2014, 9:33:00 AM Updated: July 29 2022, 10:42:32 AM
Exception based logging with .NET SDK
Summary With .NET SDK, you can do logging conditionally. You can log the SOAP request and response based on API Error Codes, SDK Exceptions and / or Http Status codes.
Detailed Description Here is an example of how to set exception based logging. /* © 2007-2014 eBay Inc., All Rights Reserved Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php */ //Create the API context object ApiContext context = new ApiContext();//Set the Credentials context.ApiCredential.ApiAccount.Developer = 'devID'; context.ApiCredential.ApiAccount.Application = 'appID'; context.ApiCredential.ApiAccount.Certificate = 'certID'; context.ApiCredential.eBayToken = 'token';
//Set the URL context.SoapApiServerUrl = 'https://api.sandbox.ebay.com/wsapi';
//Set the version context.Version = '485'; //API Error codes for logging StringCollection errorCodes = new StringCollection(); errorCodes.Add('10007'); // Internal error to the application errorCodes.Add('931'); // Invalid Token Error
//Http Status Codes for logging
Int32Collection httpCodes = new Int32Collection();
httpCodes.Add(404);
httpCodes.Add(502);
httpCodes.Add(500);
//Trigger Exceptions for logging
TypeCollection exceptions = new TypeCollection();
exceptions.Add(typeof (System.Net.ProtocolViolationException));
exceptions.Add(typeof (System.InvalidOperationException));
// Create the Exception Filter
ExceptionFilter exFilter = new ExceptionFilter();
exFilter.TriggerErrorCodes = errorCodes;
exFilter.TriggerExceptions = exceptions;
exFilter.TriggerHttpStatusCodes = httpCodes;
// Set logging Context.ApiLogManager = new ApiLogManager(); context.ApiLogManager.ApiLoggerList.Add(new eBay.Service.Util.FileLogger('Messages.log', true , true , true )); context.ApiLogManager.EnableLogging = true; //Set the filter to log messages only for specified errors / exceptions context.ApiLogManager.MessageLoggingFilter = exFilter;
Additional Resources
How well did this answer your question? Answers others found helpful