private static void UseAssemblyForDynamicInvokers(Assembly diagnosticSourceAssembly, string diagnosticSourceTypeName, string diagnosticListenerTypeName)
        {
            if (Object.ReferenceEquals(s_diagnosticSourceAssemblyInCurrentUse, diagnosticSourceAssembly))
            {
                if (Log.IsDebugLoggingEnabled)
                {
                    Log.Debug(LogComponentMoniker,
                              $"The DiagnosticSource-assembly (DS) instance being set for use by dynamic invokers"
                              + " is the same as the assembly instance already being used. Dynamic invokers will not be reset.",
                              "DS FullName", s_diagnosticSourceAssemblyInCurrentUse?.FullName,
                              "DS Location", s_diagnosticSourceAssemblyInCurrentUse?.Location,
                              "DS CodeBase", s_diagnosticSourceAssemblyInCurrentUse?.CodeBase,
                              "CurrentAppDomain.Id", AppDomain.CurrentDomain.Id,
                              "CurrentAppDomain.FriendlyName", AppDomain.CurrentDomain.FriendlyName,
                              "CurrentAppDomain.IsDefault", AppDomain.CurrentDomain.IsDefaultAppDomain());
                }

                return;
            }

            // We must be under s_setupDynamicInvokersLock when calling this method!
            // So everythign we do should be atomic in respect to re-loading DS and updating invokers.

            Type diagnosticSourceType   = diagnosticSourceAssembly.GetType(diagnosticSourceTypeName, throwOnError: true);
            Type diagnosticListenerType = diagnosticSourceAssembly.GetType(diagnosticListenerTypeName, throwOnError: true);

            // Make sure to log type info incl. AssemblyQualifiedName. In theory, types may be forwarded.

            Log.Info(LogComponentMoniker,
                     $"Setting a new instance of the DiagnosticSource-assembly (DS) for use by dynamic invokers."
                     + " Users of existing dynamic invokers may fail, and new stub instances will need to be set up to correct it.",
                     "Previous DS FullName", s_diagnosticSourceAssemblyInCurrentUse?.FullName,
                     "Previous DS Location", s_diagnosticSourceAssemblyInCurrentUse?.Location,
                     "Previous DS CodeBase", s_diagnosticSourceAssemblyInCurrentUse?.CodeBase,
                     "New DS FullName", diagnosticSourceAssembly?.FullName,
                     "New DS Location", diagnosticSourceAssembly?.Location,
                     "New DS CodeBase", diagnosticSourceAssembly?.CodeBase,
                     "DiagnosticSource type", diagnosticSourceType?.AssemblyQualifiedName,
                     "DiagnosticListener type", diagnosticListenerType?.AssemblyQualifiedName,
                     "CurrentAppDomain.Id", AppDomain.CurrentDomain.Id,
                     "CurrentAppDomain.FriendlyName", AppDomain.CurrentDomain.FriendlyName,
                     "CurrentAppDomain.IsDefault", AppDomain.CurrentDomain.IsDefaultAppDomain());

            var newInvoker = new DynamicInvoker(diagnosticSourceAssembly.FullName, diagnosticSourceType, diagnosticListenerType);

            DynamicInvoker.Current = newInvoker;

            s_diagnosticSourceAssemblyInCurrentUse = diagnosticSourceAssembly;
        }
示例#2
0
 public static bool TryGetCurrent(out DynamicInvoker currentInvoker)
 {
     currentInvoker = Volatile.Read(ref s_currentInvoker);
     return(currentInvoker != null);
 }
        public static IDisposable SubscribeDynamicInvokerInitializedListener(Action <DiagnosticSourceAssembly.IDynamicInvoker, object> dynamicInvokerInitializedAction, object state)
        {
            Validate.NotNull(dynamicInvokerInitializedAction, nameof(dynamicInvokerInitializedAction));

            return(DynamicInvoker.SubscribeInitializedListener(dynamicInvokerInitializedAction, state));
        }