/// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds an <see cref="LoggingExceptionHandler"/> based on an instance of <see cref="LoggingExceptionHandlerData"/>.
        /// </summary>
        /// <seealso cref="ExceptionHandlerCustomFactory"/>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="LoggingExceptionHandlerData"/>.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="LoggingExceptionHandler"/>.</returns>
        public IExceptionHandler Assemble(IBuilderContext context,
                                          ExceptionHandlerData objectConfiguration,
                                          IConfigurationSource configurationSource,
                                          ConfigurationReflectionCache reflectionCache)
        {
            LoggingExceptionHandlerData castedObjectConfiguration
                = (LoggingExceptionHandlerData)objectConfiguration;

            LogWriter writer;

            if (castedObjectConfiguration.UseDefaultLogger)
            {
                writer = Logger.Writer;
            }
            else
            {
                IBuilderContext logWriterContext = context.CloneForNewBuild(NamedTypeBuildKey.Make <LogWriter>(), null);
                writer = (LogWriter)logWriterContext.Strategies.ExecuteBuildUp(logWriterContext);
            }

            LoggingExceptionHandler createdObject
                = new LoggingExceptionHandler(
                      castedObjectConfiguration.LogCategory,
                      castedObjectConfiguration.EventId,
                      castedObjectConfiguration.Severity,
                      castedObjectConfiguration.Title,
                      castedObjectConfiguration.Priority,
                      castedObjectConfiguration.FormatterType,
                      writer);

            return(createdObject);
        }
Example #2
0
 private static ExceptionHandlingSettings CreateSettings()
 {
     LoggingExceptionHandlerData logData = new LoggingExceptionHandlerData("test", "cat1", 1, System.Diagnostics.TraceEventType.Error, "title", typeof(XmlExceptionFormatter), 4);
     ExceptionTypeData typeData = new ExceptionTypeData("test", typeof(Exception), PostHandlingAction.None);
     typeData.ExceptionHandlers.Add(logData);
     ExceptionPolicyData policy = new ExceptionPolicyData("test");
     policy.ExceptionTypes.Add(typeData);
     ExceptionHandlingSettings settings = new ExceptionHandlingSettings();
     settings.ExceptionPolicies.Add(policy);
     return settings;
 }
        /// <summary>
        /// Initialize a new instance of the <see cref="LoggingExceptionHandlerNode"/> class with a <see cref="LoggingExceptionHandlerData"/> instance.
        /// </summary>
        /// <param name="loggingExceptionHandlerData">A <see cref="LoggingExceptionHandlerData"/> instance.</param>
        public LoggingExceptionHandlerNode(LoggingExceptionHandlerData loggingExceptionHandlerData)
        {
            if (null == loggingExceptionHandlerData) throw new ArgumentNullException("loggingExceptionHandlerData");

            Rename(loggingExceptionHandlerData.Name);
            this.eventId = loggingExceptionHandlerData.EventId;
            this.severity = loggingExceptionHandlerData.Severity;
            this.title = loggingExceptionHandlerData.Title;
            this.formatterType = loggingExceptionHandlerData.FormatterType;
            this.logCategoryName = loggingExceptionHandlerData.LogCategory;
            this.priority = loggingExceptionHandlerData.Priority;
            this.logCategoryNodeRemoved = new EventHandler<ConfigurationNodeChangedEventArgs>(OnLogCategoryNodeRemoved);
            this.logCategoryNodeRenamed = new EventHandler<ConfigurationNodeChangedEventArgs>(OnLogCategoryNodeRenamed);
        }
        protected override void Arrange()
        {
            Logger.Reset();

            this.data =
                new LoggingExceptionHandlerData
                {
                    EventId = 100,
                    FormatterTypeName = typeof(TextExceptionFormatter).AssemblyQualifiedName,
                    LogCategory = "foo",
                    Priority = 200,
                    Severity = TraceEventType.Error
                };
        }
Example #5
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds an <see cref="LoggingExceptionHandler"/> based on an instance of <see cref="LoggingExceptionHandlerData"/>.
        /// </summary>
        /// <seealso cref="ExceptionHandlerCustomFactory"/>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="LoggingExceptionHandlerData"/>.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="LoggingExceptionHandler"/>.</returns>
        public IExceptionHandler Assemble(IBuilderContext context, ExceptionHandlerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            LoggingExceptionHandlerData castedObjectConfiguration
                = (LoggingExceptionHandlerData)objectConfiguration;

            LogWriter writer
                = (LogWriter)context.HeadOfChain.BuildUp(context, typeof(LogWriter), null, null);

            LoggingExceptionHandler createdObject
                = new LoggingExceptionHandler(
                      castedObjectConfiguration.LogCategory,
                      castedObjectConfiguration.EventId,
                      castedObjectConfiguration.Severity,
                      castedObjectConfiguration.Title,
                      castedObjectConfiguration.Priority,
                      castedObjectConfiguration.FormatterType,
                      writer);

            return(createdObject);
        }
        protected override void Arrange()
        {
            base.Arrange();

            exception.LogToCategory("Category")
                        .UsingTitle("title")
                        .UsingEventId(12)
                        .WithPriority(23)
                        .WithSeverity(TraceEventType.Stop)
                        .UsingExceptionFormatter<XmlExceptionFormatter>();

            loggingHandlerData = base.GetExceptionTypeData()
                .ExceptionHandlers
                .OfType<LoggingExceptionHandlerData>()
                .First();

        }
            protected override void Act()
            {
                var data =
                    new LoggingExceptionHandlerData
                    {
                        EventId = 100,
                        FormatterTypeName = typeof(Uri).AssemblyQualifiedName,
                        LogCategory = "foo",
                        Priority = 200,
                        Severity = TraceEventType.Error
                    };

                try
                {
                    data.BuildExceptionHandler();
                }
                catch (ConfigurationErrorsException e)
                {
                    this.exception = e;
                }
            }
            protected override void Act()
            {
                var data =
                    new LoggingExceptionHandlerData
                    {
                        EventId = 100,
                        FormatterTypeName = typeof(TestFormatter).AssemblyQualifiedName,
                        LogCategory = "foo",
                        Priority = 200,
                        Severity = TraceEventType.Error
                    };

                this.handler = (LoggingExceptionHandler)data.BuildExceptionHandler();
            }
 private void InitProperties(LoggingExceptionHandlerData data)
 {
     defaultLogCategory = data.DefaultLogCategory;
     defaultEventId = data.DefaultEventID;
     defaultSeverity = data.DefaultSeverity;
     defaultTitle = data.DefaultTitle;
     formatterTypeName = data.FormatterTypeName;
     minimumPriority = data.MinimumPriority;
 }
 protected override void Arrange()
 {
     configuration = new LoggingExceptionHandlerData();
 }