Hi, I found some sample (net 1) and I have modified it. However seems like web.config is not calling my section handler. I put some code to generate error there, seems it is never called.... Here is web.config:
<configSections>
<section name="ErrorLogs" type="BLA.ErrLog.ErrLogConfigurationHandler, ErrLogConfiguration"/>
...
<ErrorLogs name="Input Files Configuration" tracingEnabled="true">
<add name="R:\\Applications\\MISDesktop\\Error.log" regex=""/>
<add name="GLOPENU2.TXT" regex=""/>
<add name="GTIRTNS.TXT" regex=""/>
</ErrorLogs>
Here is the code of the handler (never called...):
using
System;
using
System.Configuration;
using
System.Xml;
namespace
BLA.ErrLog {
/// <summary>
/// Summary description for ContentConfigurationHandler.
/// </summary>
public class ErrLogConfigurationHandler : IConfigurationSectionHandler {
public virtual object Create(Object parent, Object context, XmlNode node) {
ErrLogConfiguration config = new ErrLogConfiguration();
config.LoadValuesFromConfigurationXml(node);
int j = 0;
int i = 9 / j;
return config;
}
}
}
Here is another file with ErrLog Class:
using System;
using System.Configuration;
using System.Collections;
using System.Xml;
using System.Collections.Specialized;
namespace BLA.ErrLog {
public class ErrLogConfiguration {
string defaultErrLog;
string inputDirectory;
string outputDirectory;
Hashtable errLogs = new Hashtable();
public static ErrLogConfiguration GetConfig() {
return (ErrLogConfiguration)ConfigurationSettings.GetConfig("ErrLog");
}
public void LoadValuesFromConfigurationXml(XmlNode node) {
XmlAttributeCollection attributeCollection = node.Attributes;
// Get the default ErrLog
defaultErrLog = attributeCollection["defaultErrLog"].Value;
inputDirectory = attributeCollection["InputDirectory"].Value;
outputDirectory = attributeCollection["OutputDirectory"].Value;
// Read child nodes
foreach (XmlNode child in node.ChildNodes) {
if (child.Name == "ErrLogs")
GetErrLogs(child);
}
}
void GetErrLogs(XmlNode node) {
foreach (XmlNode ErrLog in node.ChildNodes) {
switch (ErrLog.Name) {
case "add" :
errLogs.Add(ErrLog.Attributes["name"].Value, new ErrLog(ErrLog.Attributes) );
break;
case "remove" :
errLogs.Remove(ErrLog.Attributes["name"].Value);
break;
case "clear" :
errLogs.Clear();
break;
}
}
}
// Properties
//
public string DefaultErrLog { get { return defaultErrLog; } }
public string InputDirectory { get { return inputDirectory; } }
public string OutputDirectory { get { return outputDirectory; } }
public Hashtable ErrLogs { get { return errLogs; } }
}
public class ErrLog {
string name;
string ErrLogType;
NameValueCollection ErrLogAttributes = new NameValueCollection();
public ErrLog (XmlAttributeCollection attributes) {
// Set the name of the ErrLog
//
name = attributes["name"].Value;
// Set the type of the ErrLog
//
ErrLogType = attributes["regex"].Value;
// Store all the attributes in the attributes bucket
//
foreach (XmlAttribute attribute in attributes) {
if ( (attribute.Name != "name") && (attribute.Name != "regex") )
ErrLogAttributes.Add(attribute.Name, attribute.Value);
}
}
public string Name {
get {
return name;
}
}
public string Type {
get {
return ErrLogType;
}
}
public NameValueCollection Attributes {
get {
return ErrLogAttributes;
}
}
}
}