Beispiel #1
0
        }         // End Publish(Exception exception, NameValueCollection AdditionalInfo)

        /// <summary>
        /// Private static helper method to publish the exception information to a custom publisher.
        /// </summary>
        /// <param name="exception">The exception object whose information should be published.</param>
        /// <param name="additionalInfo">A collection of additional data that should be published along with the exception information.</param>
        /// <param name="publisher">The PublisherSettings that contains the values of the publishers configuration.</param>
        private static void PublishToCustomPublisher(Exception exception, NameValueCollection additionalInfo, PublisherSettings publisher)
        {
            try
            {
                // Check if the exception format is "xml".
                if (publisher.ExceptionFormat == PublisherFormat.Xml)
                {
                    // If it is load the IExceptionXmlPublisher interface on the custom publisher.

                    // Instantiate the class
                    IExceptionXmlPublisher XMLPublisher = (IExceptionXmlPublisher)Activate(publisher.AssemblyName, publisher.TypeName);

                    // Publish the exception and any additional information
                    XMLPublisher.Publish(SerializeToXml(exception, additionalInfo), publisher.OtherAttributes);
                }
                // Otherwise load the IExceptionPublisher interface on the custom publisher.
                else
                {
                    // Instantiate the class
                    IExceptionPublisher Publisher = (IExceptionPublisher)Activate(publisher.AssemblyName, publisher.TypeName);

                    // Publish the exception and any additional information
                    Publisher.Publish(exception, additionalInfo, publisher.OtherAttributes);
                }
            }
            catch (Exception e)
            {
                CustomPublisherException publisherException = new CustomPublisherException(resourceManager.GetString("RES_CUSTOM_PUBLISHER_FAILURE_MESSAGE"), publisher.AssemblyName, publisher.TypeName, publisher.ExceptionFormat, e);
                publisherException.AdditionalInformation.Add(publisher.OtherAttributes);

                throw(publisherException);
            }
        }