/// <summary> /// Register a distributed logger. This involves creating a new eventsource sink /// and associating this with the central logger. In addition the sinkId needs /// to be put in the loggerDescription so that nodes know what they need to /// tag onto the event so that the message goes to the correct logger. /// /// The central logger is initialized before the distributed logger /// </summary> /// <param name="centralLogger">Central logger to receive messages from the forwarding logger, This logger cannot have been registered before</param> /// <param name="forwardingLogger">Logger description which describes how to create the forwarding logger, the logger description cannot have been used before</param> /// <returns value="bool">True if the distributed and central logger were registered, false if they either were already registered</returns> /// <exception cref="InternalErrorException">If forwardingLogger is null</exception> /// <exception cref="LoggerException">If a logger exception is thrown while creating or initializing the distributed or central logger</exception> /// <exception cref="InternalLoggerException">If any exception (other than a loggerException)is thrown while creating or initializing the distributed or central logger, we will wrap these exceptions in an InternalLoggerException</exception> public bool RegisterDistributedLogger(ILogger centralLogger, LoggerDescription forwardingLogger) { lock (_lockObject) { ErrorUtilities.VerifyThrow(_serviceState != LoggingServiceState.Shutdown, " The object is shutdown, should not do any operations on a shutdown component"); ErrorUtilities.VerifyThrow(forwardingLogger != null, "forwardingLogger was null"); if (centralLogger == null) { centralLogger = new NullCentralLogger(); } IForwardingLogger localForwardingLogger = null; // create an eventSourceSink which the central logger will register with to receive the events from the forwarding logger EventSourceSink eventSourceSink = new EventSourceSink(); // If the logger is already in the list it should not be registered again. if (_iloggerList.Contains(centralLogger)) { return false; } // Assign a unique logger Id to this distributed logger int sinkId = _nextSinkId++; forwardingLogger.LoggerId = sinkId; eventSourceSink.Name = "Sink for forwarding logger \"" + sinkId + "\"."; // Initialize and register the central logger InitializeLogger(centralLogger, eventSourceSink); localForwardingLogger = forwardingLogger.CreateForwardingLogger(); EventRedirectorToSink newRedirector = new EventRedirectorToSink(sinkId, eventSourceSink); localForwardingLogger.BuildEventRedirector = newRedirector; localForwardingLogger.Parameters = forwardingLogger.LoggerSwitchParameters; localForwardingLogger.Verbosity = forwardingLogger.Verbosity; // Give the forwarding logger registered on the inproc node the correct ID. localForwardingLogger.NodeId = 1; // Convert the path to the logger DLL to full path before passing it to the node provider forwardingLogger.ConvertPathsToFullPaths(); CreateFilterEventSource(); // Initialize and register the forwarding logger InitializeLogger(localForwardingLogger, _filterEventSource); _loggerDescriptions.Add(forwardingLogger); _eventSinkDictionary.Add(sinkId, eventSourceSink); return true; } }