public void SetUp()
 {
     provider            = new LoggingExceptionHandlerDataManageabilityProvider();
     machineKey          = new MockRegistryKey(true);
     userKey             = new MockRegistryKey(true);
     configurationObject = new LoggingExceptionHandlerData();
 }
예제 #2
0
        public void LoggingExceptionHandlerDataPropertiesTest()
        {
            LoggingExceptionHandlerData data = new LoggingExceptionHandlerData();
            string   defaultLogCategory      = "default log category";
            int      defaultEventID          = 5;
            Severity defaultSeverity         = Severity.Error;
            int      minimumPriority         = 2;
            string   defaultTitle            = "default title";
            string   formatterTypeName       = "typeName";
            string   typeName = typeof(LoggingExceptionHandler).AssemblyQualifiedName;

            data.DefaultLogCategory = defaultLogCategory;
            data.DefaultEventID     = defaultEventID;
            data.DefaultSeverity    = defaultSeverity;
            data.DefaultTitle       = defaultTitle;
            data.FormatterTypeName  = formatterTypeName;
            data.MinimumPriority    = minimumPriority;

            Assert.AreEqual(defaultLogCategory, data.DefaultLogCategory);
            Assert.AreEqual(defaultEventID, data.DefaultEventID);
            Assert.AreEqual(defaultSeverity, data.DefaultSeverity);
            Assert.AreEqual(defaultTitle, data.DefaultTitle);
            Assert.AreEqual(formatterTypeName, data.FormatterTypeName);
            Assert.AreEqual(typeName, data.TypeName);
            Assert.AreEqual(minimumPriority, data.MinimumPriority);
        }
        public void LoggingHandlerNodeDataTest()
        {
            string         name          = "some name";
            int            eventId       = 3234;
            int            priority      = -1;
            Type           formatterType = typeof(Guid);
            TraceEventType severity      = TraceEventType.Resume;

            LoggingExceptionHandlerData data = new LoggingExceptionHandlerData();

            data.Name          = name;
            data.EventId       = eventId;
            data.FormatterType = formatterType;
            data.Priority      = priority;
            data.Severity      = severity;
            data.Title         = "Title";
            data.LogCategory   = "Category1";

            LoggingExceptionHandlerNode node = new LoggingExceptionHandlerNode(data);

            node.LogCategory      = new CategoryTraceSourceNode();
            node.LogCategory.Name = "Category1";
            Assert.AreEqual(data.Name, node.Name);
            Assert.AreEqual(data.EventId, node.EventId);
            Assert.AreEqual(formatterType, node.FormatterType);
            Assert.AreEqual(data.Priority, node.Priority);
            Assert.AreEqual(data.Severity, node.Severity);
            Assert.AreEqual(data.Title, node.Title);
            Assert.AreEqual(data.LogCategory, node.LogCategory.Name);
        }
예제 #4
0
        public void CanReadAndWriteLoggingHandler()
        {
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();

            fileMap.ExeConfigFilename = "test.exe.config";
            System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            config.Sections.Remove(ExceptionHandlingSettings.SectionName);
            config.Sections.Add(ExceptionHandlingSettings.SectionName, CreateSettings());
            config.Save(ConfigurationSaveMode.Full);

            config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            ExceptionHandlingSettings   settings = (ExceptionHandlingSettings)config.Sections[ExceptionHandlingSettings.SectionName];
            LoggingExceptionHandlerData data     = (LoggingExceptionHandlerData)settings.ExceptionPolicies.Get("test").ExceptionTypes.Get("test").ExceptionHandlers.Get("test");

            config.Sections.Remove(ExceptionHandlingSettings.SectionName);
            config.Save(ConfigurationSaveMode.Full);

            Assert.AreEqual("test", data.Name);
            Assert.AreEqual("cat1", data.LogCategory);
            Assert.AreEqual(1, data.EventId);
            Assert.AreEqual(TraceEventType.Error, data.Severity);
            Assert.AreEqual("title", data.Title);
            Assert.AreEqual(typeof(XmlExceptionFormatter), data.FormatterType);
            Assert.AreEqual(4, data.Priority);
        }
        public void LoggingHandlerNodeTest()
        {
            string         name          = "some name";
            int            eventId       = 3234;
            int            priority      = -1;
            Type           formatterType = typeof(Guid);
            TraceEventType severity      = TraceEventType.Resume;


            LoggingExceptionHandlerData loggingHandlerData = new LoggingExceptionHandlerData();

            loggingHandlerData.Name          = name;
            loggingHandlerData.EventId       = eventId;
            loggingHandlerData.Priority      = priority;
            loggingHandlerData.FormatterType = formatterType;
            loggingHandlerData.Severity      = severity;

            LoggingExceptionHandlerNode exceptionHandlerNode = new LoggingExceptionHandlerNode(loggingHandlerData);

            ApplicationNode.AddNode(exceptionHandlerNode);

            LoggingExceptionHandlerData nodeData = (LoggingExceptionHandlerData)exceptionHandlerNode.ExceptionHandlerData;

            Assert.AreEqual(name, nodeData.Name);
            Assert.AreEqual(eventId, nodeData.EventId);
            Assert.AreEqual(formatterType, nodeData.FormatterType);
            Assert.AreEqual(priority, nodeData.Priority);
            Assert.AreEqual(severity, nodeData.Severity);
        }
예제 #6
0
        public void LoggingExceptionHandlerDataPropertiesTest()
        {
            LoggingExceptionHandlerData data = new LoggingExceptionHandlerData();
            string defaultLogCategory = "default log category";
            int defaultEventID = 5;
            Severity defaultSeverity = Severity.Error;
            int minimumPriority = 2;
            string defaultTitle = "default title";
            string formatterTypeName = "typeName";
            string typeName = typeof(LoggingExceptionHandler).AssemblyQualifiedName;

            data.DefaultLogCategory = defaultLogCategory;
            data.DefaultEventID = defaultEventID;
            data.DefaultSeverity = defaultSeverity;
            data.DefaultTitle = defaultTitle;
            data.FormatterTypeName = formatterTypeName;
            data.MinimumPriority = minimumPriority;

            Assert.AreEqual(defaultLogCategory, data.DefaultLogCategory);
            Assert.AreEqual(defaultEventID, data.DefaultEventID);
            Assert.AreEqual(defaultSeverity, data.DefaultSeverity);
            Assert.AreEqual(defaultTitle, data.DefaultTitle);
            Assert.AreEqual(formatterTypeName, data.FormatterTypeName);
            Assert.AreEqual(typeName, data.TypeName);
            Assert.AreEqual(minimumPriority, data.MinimumPriority);
        }
        public void LoggingHandlerNodeDataTest()
        {
            string name = "some name";
            int eventId = 3234;
            int priority = -1;
            Type formatterType = typeof(Guid);
            TraceEventType severity = TraceEventType.Resume;

            LoggingExceptionHandlerData data = new LoggingExceptionHandlerData();
            data.Name = name;
            data.EventId = eventId;
            data.FormatterType = formatterType;
            data.Priority = priority;
            data.Severity = severity;
            data.Title = "Title";
            data.LogCategory = "Category1";

            LoggingExceptionHandlerNode node = new LoggingExceptionHandlerNode(data);
            node.LogCategory = new CategoryTraceSourceNode();
            node.LogCategory.Name = "Category1";
            Assert.AreEqual(data.Name, node.Name);
            Assert.AreEqual(data.EventId, node.EventId);
            Assert.AreEqual(formatterType, node.FormatterType);
            Assert.AreEqual(data.Priority, node.Priority);
            Assert.AreEqual(data.Severity, node.Severity);
            Assert.AreEqual(data.Title, node.Title);
            Assert.AreEqual(data.LogCategory, node.LogCategory.Name);
        }
 public void SetUp()
 {
     provider = new LoggingExceptionHandlerDataManageabilityProvider();
     machineKey = new MockRegistryKey(true);
     userKey = new MockRegistryKey(true);
     configurationObject = new LoggingExceptionHandlerData();
 }
예제 #9
0
 public void SetUp()
 {
     provider            = new ConfigurationElementManageabilityProviderWrapper(new LoggingExceptionHandlerDataManageabilityProvider());
     machineKey          = new MockRegistryKey(true);
     userKey             = new MockRegistryKey(true);
     wmiSettings         = new List <ConfigurationSetting>();
     configurationObject = new LoggingExceptionHandlerData();
 }
예제 #10
0
 private void InitProperties(LoggingExceptionHandlerData data)
 {
     defaultLogCategory = data.DefaultLogCategory;
     defaultEventId     = data.DefaultEventID;
     defaultSeverity    = data.DefaultSeverity;
     defaultTitle       = data.DefaultTitle;
     formatterTypeName  = data.FormatterTypeName;
     minimumPriority    = data.MinimumPriority;
 }
        public static bool SaveChanges(LoggingExceptionHandlerSetting loggingExceptionHandlerSettingSetting, ConfigurationElement sourceElement)
        {
            LoggingExceptionHandlerData element = (LoggingExceptionHandlerData)sourceElement;

            element.EventId           = loggingExceptionHandlerSettingSetting.EventId;
            element.Title             = loggingExceptionHandlerSettingSetting.Title;
            element.Priority          = loggingExceptionHandlerSettingSetting.Priority;
            element.LogCategory       = loggingExceptionHandlerSettingSetting.LogCategory;
            element.FormatterTypeName = loggingExceptionHandlerSettingSetting.FormatterType;
            return(true);
        }
예제 #12
0
            public ExceptionConfigurationLoggingProviderBuilder(IExceptionConfigurationAddExceptionHandlers context, string categoryName)
                : base(context)
            {
                logHandler = new LoggingExceptionHandlerData
                {
                    Name          = categoryName,
                    LogCategory   = categoryName,
                    FormatterType = typeof(TextExceptionFormatter)
                };

                base.CurrentExceptionTypeData.ExceptionHandlers.Add(logHandler);
            }
 public static void GenerateWmiObjects(LoggingExceptionHandlerData configurationObject,
                                       ICollection <ConfigurationSetting> wmiSettings)
 {
     wmiSettings.Add(
         new LoggingExceptionHandlerSetting(configurationObject,
                                            configurationObject.Name,
                                            configurationObject.EventId,
                                            configurationObject.FormatterType.AssemblyQualifiedName,
                                            configurationObject.LogCategory,
                                            configurationObject.Priority,
                                            configurationObject.Severity.ToString(),
                                            configurationObject.Title));
 }
            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();
            }
        protected override void Arrange()
        {
            Logger.Reset();

            this.data =
                new LoggingExceptionHandlerData
            {
                EventId           = 100,
                FormatterTypeName = typeof(TextExceptionFormatter).AssemblyQualifiedName,
                LogCategory       = "foo",
                Priority          = 200,
                Severity          = TraceEventType.Error
            };
        }
예제 #16
0
        static ExceptionHandlingSettings CreateSettings()
        {
            LoggingExceptionHandlerData logData  = new LoggingExceptionHandlerData("test", "cat1", 1, 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);
        }
        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();
        }
예제 #18
0
        /// <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.formatterTypeName      = loggingExceptionHandlerData.FormatterTypeName;
            this.logCategoryName        = loggingExceptionHandlerData.LogCategory;
            this.priority               = loggingExceptionHandlerData.Priority;
            this.logCategoryNodeRemoved = new EventHandler <ConfigurationNodeChangedEventArgs>(OnLogCategoryNodeRemoved);
            this.logCategoryNodeRenamed = new EventHandler <ConfigurationNodeChangedEventArgs>(OnLogCategoryNodeRenamed);
        }
            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;
                }
            }
예제 #20
0
        void IContainerPolicyCreator.CreatePolicies(
            IPolicyList policyList,
            string instanceName,
            ConfigurationElement configurationObject,
            IConfigurationSource configurationSource)
        {
            LoggingExceptionHandlerData castConfigurationObject = (LoggingExceptionHandlerData)configurationObject;

            new PolicyBuilder <LoggingExceptionHandler, LoggingExceptionHandlerData>(
                NamedTypeBuildKey.Make <LoggingExceptionHandler>(instanceName),
                castConfigurationObject,
                c => new LoggingExceptionHandler(
                    castConfigurationObject.LogCategory,
                    castConfigurationObject.EventId,
                    castConfigurationObject.Severity,
                    castConfigurationObject.Title,
                    castConfigurationObject.Priority,
                    castConfigurationObject.FormatterType,
                    Resolve.Reference <LogWriter>(null)))
            .AddPoliciesToPolicyList(policyList);
        }
        public void SavesChangesToConfigurationObject()
        {
            LoggingExceptionHandlerData sourceElement = new LoggingExceptionHandlerData("name",
                                                                                        "LogCategory",
                                                                                        0,
                                                                                        System.Diagnostics.TraceEventType.Error,
                                                                                        "Title",
                                                                                        typeof(String).AssemblyQualifiedName,
                                                                                        0);
            List <ConfigurationSetting> settings = new List <ConfigurationSetting>(1);

            LoggingExceptionHandlerDataWmiMapper.GenerateWmiObjects(sourceElement, settings);
            Assert.AreEqual(1, settings.Count);
            LoggingExceptionHandlerSetting setting = settings[0] as LoggingExceptionHandlerSetting;

            Assert.IsNotNull(setting);
            setting.Title         = "Changed";
            setting.FormatterType = typeof(bool).AssemblyQualifiedName;
            setting.Commit();
            Assert.AreEqual(setting.FormatterType, sourceElement.FormatterTypeName);
            Assert.AreEqual(setting.Title, sourceElement.Title);
        }
예제 #22
0
        public void ReturnsTypeRegistrationForLoggingHandlerData()
        {
            var handlerData = new LoggingExceptionHandlerData(
                handlerName111, handlerCategory111, 100, TraceEventType.Information, handlerMessage111,
                typeof(ExceptionFormatter), 101);

            var registration = handlerData.GetRegistrations("prefix").First();

            registration.AssertForServiceType(typeof(IExceptionHandler))
            .ForName("prefix." + handlerName111)
            .ForImplementationType(typeof(LoggingExceptionHandler));



            registration.AssertConstructor()
            .WithValueConstructorParameter(handlerCategory111)
            .WithValueConstructorParameter(100)
            .WithValueConstructorParameter(TraceEventType.Information)
            .WithValueConstructorParameter(handlerMessage111)
            .WithValueConstructorParameter(101)
            .WithValueConstructorParameter(typeof(ExceptionFormatter))
            .WithContainerResolvedParameter <LogWriter>(null)
            .VerifyConstructorParameters();
        }
        public void ReturnsTypeRegistrationForLoggingHandlerData()
        {
            var handlerData = new LoggingExceptionHandlerData(
                handlerName111, handlerCategory111, 100, TraceEventType.Information, handlerMessage111,
                typeof (ExceptionFormatter), 101);

            var registration = handlerData.GetRegistrations("prefix").First();

            registration.AssertForServiceType(typeof(IExceptionHandler))
                .ForName("prefix." + handlerName111)
                .ForImplementationType(typeof (LoggingExceptionHandler));



            registration.AssertConstructor()
                .WithValueConstructorParameter(handlerCategory111)
                .WithValueConstructorParameter(100)
                .WithValueConstructorParameter(TraceEventType.Information)
                .WithValueConstructorParameter(handlerMessage111)
                .WithValueConstructorParameter(101)
                .WithValueConstructorParameter(typeof(ExceptionFormatter))                
                .WithContainerResolvedParameter<LogWriter>(null)
                .VerifyConstructorParameters();
        }
 /// <summary>
 /// Constructs the node with config data.
 /// </summary>
 /// <param name="data">The config data to initialize this node.</param>
 public LoggingExceptionHandlerNode(LoggingExceptionHandlerData data) : base(data)
 {
     this.data = data;
     this.onDefaultCategoryNodeRemoved = new ConfigurationNodeChangedEventHandler(OnDefaultCategoryNodeRemoved);
 }
        public void LoggingHandlerNodeTest()
        {
            string name = "some name";
            int eventId = 3234;
            int priority = -1;
            Type formatterType = typeof(Guid);
            TraceEventType severity = TraceEventType.Resume;

            LoggingExceptionHandlerData loggingHandlerData = new LoggingExceptionHandlerData();
            loggingHandlerData.Name = name;
            loggingHandlerData.EventId = eventId;
            loggingHandlerData.Priority = priority;
            loggingHandlerData.FormatterType = formatterType;
            loggingHandlerData.Severity = severity;

            LoggingExceptionHandlerNode exceptionHandlerNode = new LoggingExceptionHandlerNode(loggingHandlerData);
            ApplicationNode.AddNode(exceptionHandlerNode);

            LoggingExceptionHandlerData nodeData = (LoggingExceptionHandlerData) exceptionHandlerNode.ExceptionHandlerData;
            Assert.AreEqual(name, nodeData.Name);
            Assert.AreEqual(eventId, nodeData.EventId);
            Assert.AreEqual(formatterType, nodeData.FormatterType);
            Assert.AreEqual(priority, nodeData.Priority);
            Assert.AreEqual(severity, nodeData.Severity);
        }
 protected override void Arrange()
 {
     configuration = new LoggingExceptionHandlerData();
 }
예제 #27
0
 /// <summary>
 /// Constructs the node with config data.
 /// </summary>
 /// <param name="data">The config data to initialize this node.</param>
 public LoggingExceptionHandlerNode(LoggingExceptionHandlerData data)
     : base(data)
 {
     this.data = data;
     this.onDefaultCategoryNodeRemoved = new ConfigurationNodeChangedEventHandler(OnDefaultCategoryNodeRemoved);
 }