Beispiel #1
0
 static LogFactory()
 {
   try
   {
     ReferencingAssembly = GetReferencingAssembly();
     AbstractConfigurator Configurator = new ConfigFileConfigurator();        
     if (ReferencingAssembly != null)
     {
       object[] Attribs = ReferencingAssembly.GetCustomAttributes(typeof(ConfiguratorAttribute), false);
       if (Attribs != null)
       {
         if (Attribs.Length == 1)
         {
           if (Attribs[0] is ConfiguratorAttribute)
           {
             Configurator = ((ConfiguratorAttribute)Attribs[0]).Configurator;
           }
         }
       }
     }
     Categories = Configurator.GetCategories(ref DefaultName);                
   }
   finally
   {
   }
   if (DefaultName == null)
   {
     if (Categories.Count > 0)
     {
       DefaultName = (string)Categories.GetKey(0);
     }
     else
     {
       Category Temp = new Category();
       Temp.Name = "Default";
       Temp.Initialize();
       Categories.Add("Default", Temp);
       DefaultName = "Default";
     }
   }
 }
Beispiel #2
0
 static LogFactory()
 {
     try
     {
         ReferencingAssembly = GetReferencingAssembly();
         AbstractConfigurator Configurator = new ConfigFileConfigurator();
         if (ReferencingAssembly != null)
         {
             object[] Attribs = ReferencingAssembly.GetCustomAttributes(typeof(ConfiguratorAttribute), false);
             if (Attribs != null)
             {
                 if (Attribs.Length == 1)
                 {
                     if (Attribs[0] is ConfiguratorAttribute)
                     {
                         Configurator = ((ConfiguratorAttribute)Attribs[0]).Configurator;
                     }
                 }
             }
         }
         Categories = Configurator.GetCategories(ref DefaultName);
     }
     finally
     {
     }
     if (DefaultName == null)
     {
         if (Categories.Count > 0)
         {
             DefaultName = (string)Categories.GetKey(0);
         }
         else
         {
             Category Temp = new Category();
             Temp.Name = "Default";
             Temp.Initialize();
             Categories.Add("Default", Temp);
             DefaultName = "Default";
         }
     }
 }
        public override UniqueNameObjectCollection GetCategories(ref string DefaultCategory)
        {
            UniqueNameObjectCollection Categories = new UniqueNameObjectCollection();
            XmlNode XNode = (XmlNode)ConfigurationSettings.GetConfig("TerWoord/Logger.NET");

            if (XNode == null)
            {
                Categories.Add("default", new Category());
                DefaultCategory = "default";
                return(Categories);
            }
            StringReader  SR;
            XmlSerializer XS = new XmlSerializer(typeof(Category));

            Categories.Clear();
            foreach (XmlNode xn in XNode.ChildNodes)
            {
                if (xn is XmlElement)
                {
                    if (xn.Name == "Default")
                    {
                        if (xn.Attributes["Name"] != null &&
                            xn.Attributes["Name"].Value != null)
                        {
                            DefaultCategory = xn.Attributes["Name"].Value;
                        }
                    }
                    else
                    {
                        SR = new StringReader(xn.OuterXml);
                        Category c = (Category)XS.Deserialize(SR);
                        c.Initialize();
                        Categories.Add(c.Name, c);
                    }
                }
            }
            return(Categories);
        }
Beispiel #4
0
        public override UniqueNameObjectCollection GetCategories(ref string DefaultCategory)
        {
            UniqueNameObjectCollection Categories = new UniqueNameObjectCollection();

            try
            {
                if (_XmlFile.IndexOf("${ASSEMBLYDIR}") != -1)
                {
                    string TempDir = @"c:\";
                    try
                    {
                        TempDir = Path.GetDirectoryName(LogFactory.ReferencingAssembly.Location);
                    }
                    catch
                    {
                        TempDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Logger.NET");
                    }
                    Directory.CreateDirectory(TempDir);
                    if (TempDir.EndsWith(Path.DirectorySeparatorChar.ToString())
                        | TempDir.EndsWith(Path.AltDirectorySeparatorChar.ToString())
                        )
                    {
                        _XmlFile = _XmlFile.Replace("${ASSEMBLYDIR}", TempDir);
                    }
                    else
                    {
                        _XmlFile = _XmlFile.Replace("${ASSEMBLYDIR}", TempDir + Path.DirectorySeparatorChar);
                    }
                }
                if (File.Exists(_XmlFile))
                {
                    XmlDocument XmlDoc = new XmlDocument();
                    XmlDoc.Load(_XmlFile);
                    XmlNode XNode = XmlDoc.SelectSingleNode("/TerWoord/Logger.NET");
                    if (XNode == null)
                    {
                        Categories.Add("default", new Category());
                        DefaultCategory = "default";
                        return(Categories);
                    }
                    StringReader  SR;
                    XmlSerializer XS = new XmlSerializer(typeof(Category));
                    Categories.Clear();
                    foreach (XmlNode xn in XNode.ChildNodes)
                    {
                        if (xn is XmlElement)
                        {
                            if (xn.Name == "Default")
                            {
                                if (xn.Attributes["Name"] != null &&
                                    xn.Attributes["Name"].Value != null)
                                {
                                    DefaultCategory = xn.Attributes["Name"].Value;
                                }
                            }
                            else
                            {
                                SR = new StringReader(xn.OuterXml);
                                Category c = (Category)XS.Deserialize(SR);
                                c.Initialize();
                                Categories.Add(c.Name, c);
                            }
                        }
                    }
                    return(Categories);
                }
            }
            catch
            {
                Categories.Add("default", new Category());
                DefaultCategory = "default";
                throw;
            }
            return(new UniqueNameObjectCollection());
        }