Enabling communication traces in C# application for Azure AD authentication with SQL DB using token-based mechanism with Multi-factor authentication (MFA)

SQL server security team presents a code sample ( as VS project) allowing to enable communication traces for ADAL managed library used to support Universal Authentication with MFA for SQL DB ( see also Azure AD authentication extensions for Azure SQL DB and SQL DW tools). The ADAL traces help to troubleshoot communication issues related to Azure AD and ADAL authentication. The attached C# code sample is based on existing blog post Token-based authentication including Multi-factor auth (MFA) for Azure SQL DB using Azure Active Directory (AD) (see the details there) and was extended by the ADAL traces. The sample below collects all ADAL traces and writes them to the application console. Please note that it is possible to choose different level of tracing (see the comments in the main program). For further questions on this topic please contact SQLAADAuth@microsoft.com alias.