/// <summary> /// Add a tracing interceptor to be notified of changes. /// </summary> /// <param name="interceptor">The tracing interceptor.</param> public static void AddTracingInterceptor(IServiceClientTracingInterceptor interceptor) { if (interceptor == null) { throw new ArgumentNullException("interceptor"); } lock (_lock) { _interceptors.Add(interceptor); _threadSafeInterceptors = new List <IServiceClientTracingInterceptor>(_interceptors); } }
/// <summary> /// Add a tracing interceptor to be notified of changes. /// </summary> /// <param name="interceptor">The tracing interceptor.</param> public static void AddTracingInterceptor(IServiceClientTracingInterceptor interceptor) { if (interceptor == null) { throw new ArgumentNullException("interceptor"); } lock (_lock) { _interceptors.Add(interceptor); _threadSafeInterceptors = new List<IServiceClientTracingInterceptor>(_interceptors); } }
public DataLakeStoreTraceLogger(Cmdlet commandToLog, string logFilePath = null, LogLevel logLevel = LogLevel.Information) { LogFilePath = logFilePath; LogLevel = logLevel; if (Directory.Exists(LogFilePath)) // the user passed in a directory instead of a file { commandToLog.WriteWarning(string.Format(Resources.DiagnosticDirectoryAlreadyExists, LogFilePath)); return; } try { // always create the directory, since it is a no-op if the path exists // we also do not do heavy validation here, since any exception will be caught and reported back as a warning. Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath)); TraceStream = new FileStream(LogFilePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite); } catch (Exception ex) { commandToLog.WriteWarning(string.Format(Resources.TraceStreamFailure, LogFilePath, ex.Message)); return; } TextListener = new TextWriterTraceListener(TraceStream); Trace.CorrelationManager.ActivityId = Guid.NewGuid(); PreviousAutoFlush = Trace.AutoFlush; Trace.Listeners.Add(TextListener); Trace.AutoFlush = true; SdkTracingInterceptor = new DataLakeStoreTracingInterceptor(this); PreviousAdalSourceLevel = AdalTrace.TraceSource.Switch.Level; PreviousAdalTraceLevel = AdalTrace.LegacyTraceSwitch.Level; // Ignore ADAL trace logs if debug logging isn't selected. if (LogLevel != LogLevel.Debug) { AdalTrace.TraceSource.Switch.Level = SourceLevels.Warning; AdalTrace.LegacyTraceSwitch.Level = TraceLevel.Warning; } if (SdkTracingInterceptor != null) { ServiceClientTracing.AddTracingInterceptor(SdkTracingInterceptor); } }
/// <summary> /// Remove a tracing interceptor from change notifications. /// </summary> /// <param name="interceptor">The tracing interceptor.</param> /// <returns>True if the tracing interceptor was found and removed; false otherwise.</returns> public static bool RemoveTracingInterceptor(IServiceClientTracingInterceptor interceptor) { if (interceptor == null) { throw new ArgumentNullException("interceptor"); } bool removed; lock (_lock) { removed = _interceptors.Remove(interceptor); if (removed) { _threadSafeInterceptors = new List <IServiceClientTracingInterceptor>(_interceptors); } } return(removed); }
/// <summary> /// Remove a tracing interceptor from change notifications. /// </summary> /// <param name="interceptor">The tracing interceptor.</param> /// <returns>True if the tracing interceptor was found and removed; false otherwise.</returns> public static bool RemoveTracingInterceptor(IServiceClientTracingInterceptor interceptor) { if (interceptor == null) { throw new ArgumentNullException("interceptor"); } bool removed; lock (_lock) { removed = _interceptors.Remove(interceptor); if (removed) { _threadSafeInterceptors = new List<IServiceClientTracingInterceptor>(_interceptors); } } return removed; }