I’m trying to troubleshoot a problem we are having sporadically with Office365 Exchange web service. Here is the error we are seeing:
The underlying connection was closed: An unexpected error occurred on a send.
We get this error during the EWSClient.GetEWSClient() call such as when trying to authenticate to Office365:
var tokenProvider = new AzureROPCTokenProvider(azureDirectoryID, azureApplicationID, azureClientSecret, exchangeUsername, exchangePassword);
var credentials = new OAuthNetworkCredential(tokenProvider);
// Exception occurs on the next line.
var exchange = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", credentials);
I would like to use the logging for Exchange Clients as described here: Utility Features|Documentation
However, we are running this code in a separate App Domain from a main Windows Service process (eg. within a plugin module) so adding to app.config of the running Windows Service doesn’t seem to transfer to where the code is running.
I have tried to set the IEWSClient.LogFileName after the EWSClient is created, which works, but the logging is activated only after the authentication process is completed successfully. If there is a problem during the initial call, logging is never activated and we just see an Exception thrown with the error described above.
My question is whether there is a way to activate logging BEFORE the call to EWSClient.GetEWSClient(), without using app.config, so I can capture any logging details when a failure occurs during authentication.
I’m hoping I might be able to gather some additional details that will help identify the problem we are having.