private void Log(LogLevel msalLogLevel, string messageWithPii, string messageScrubbed) { if (msalLogLevel > Logger.Level) { return; } //format log message; string correlationId = CorrelationId.Equals(Guid.Empty) ? string.Empty : " - " + CorrelationId; var msalIdParameters = MsalIdHelper.GetMsalIdParameters(); string os = "N/A"; if (msalIdParameters.TryGetValue(MsalIdParameter.OS, out string osValue)) { os = osValue; } bool messageWithPiiExists = !string.IsNullOrWhiteSpace(messageWithPii); // If we have a message with PII, and PII logging is enabled, use the PII message, else use the scrubbed message. bool isLoggingPii = messageWithPiiExists && Logger.PiiLoggingEnabled; string messageToLog = isLoggingPii ? messageWithPii : messageScrubbed; string log = string.Format(CultureInfo.InvariantCulture, "{0} MSAL {1} {2} {3} [{4}{5}]{6} {7}", isLoggingPii ? "(True)" : "(False)", MsalIdHelper.GetMsalVersion(), msalIdParameters[MsalIdParameter.Product], os, DateTime.UtcNow, correlationId, Component, messageToLog); if (Logger.DefaultLoggingEnabled) { switch (Logger.Level) { case LogLevel.Error: _platformLogger.Error(log); break; case LogLevel.Warning: _platformLogger.Warning(log); break; case LogLevel.Info: _platformLogger.Information(log); break; case LogLevel.Verbose: _platformLogger.Verbose(log); break; } } ExecuteCallback(msalLogLevel, log, isLoggingPii); }
private static Assembly LoadPlatformSpecificAssembly() { // For security reasons, it is important to have PublicKeyToken mentioned referencing the assembly. const string PlatformSpecificAssemblyNameTemplate = "Microsoft.Identity.Client.Platform, Version={0}, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae"; string platformSpecificAssemblyName = string.Format(CultureInfo.InvariantCulture, PlatformSpecificAssemblyNameTemplate, MsalIdHelper.GetMsalVersion()); try { return(Assembly.Load(new AssemblyName(platformSpecificAssemblyName))); } catch (FileNotFoundException ex) { PlatformPlugin.Logger.Error(null, ex); throw new MsalException(MsalError.AssemblyNotFound, string.Format(CultureInfo.InvariantCulture, MsalErrorMessage.AssemblyNotFoundTemplate, platformSpecificAssemblyName), ex); } catch (Exception ex) // FileLoadException is missing from PCL { PlatformPlugin.Logger.Error(null, ex); throw new MsalException(MsalError.AssemblyLoadFailed, string.Format(CultureInfo.InvariantCulture, MsalErrorMessage.AssemblyLoadFailedTemplate, platformSpecificAssemblyName), ex); } }