How to Activate EWSClient Logging without Using app.config?

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.

@dknudsen-bhip,
Thank you for the issue description.

Unfortunately, I have not found any information about this. I logged the issue with ID EMAILNET-40458 in our tracking system. Our development team will consider such an ability. We will let you know as soon as possible.

SOLVED:

After some additional troubleshooting, I was able to discover that the log files were actually being created using the Windows Service app.config settings, as described in the Aspose help article referenced above.

I was using a path like “…\folder\filename.log” in app.config, assuming that the root path was where the main executable was running from. Well, it wasn’t, “C:\Windows\System32” was the root path. So once I figured that out, I found where the log files were being saved.

I changed the “EWSDiagnosticLog” location to a static location (rather than relative) where I want the logs to be saved and it is working as expected now.

@Andrey_Potapov - The EMAILNET-40458 ticket can be closed. I guess the only thing that could be done would be to change the examples to use a static folder path as an example or maybe better, to add a warning/note stating that the files might not be saved where you first think. :slight_smile: Thanks for your quick response.

@dknudsen-bhip,
We are glad you found the solution.

I will pass your suggestion to our team.