EDN Admin
Well-known member
Hi,
i have following App.Config file:
<?xml version="1.0"?><br/>
<configuration><br/>
<configSections><br/>
<section name="RUCVD-03" type="System.Configuration.AppSettingsSection"/><br/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/><br/>
<section name="EventTraceHelper" type="System.Configuration.AppSettingsSection"/><br/>
<!-- Add this section if you need to change Errorhelper settings--><br/>
<section name="EMHelper" type="System.Configuration.AppSettingsSection"/><br/>
</configSections><br/>
<appSettings><br/>
<!--Device, or Entity running, NAN-15, Tango-11, OCD-02, or others--><br/>
<add key="DeviceName" value="RUCVD-03"/><br/>
</appSettings><br/>
<!-- START Error Helper config Settings OPTIONAL see Help for all params--><br/>
<EMHelper><br/>
<add key="DatabaseName" value="ERRORMANAGEMENT"/><br/>
<add key="DatabaseType" value="Development"/><br/>
<add key="TSDSystem" value="TEST"/><br/>
<add key="ConnectionType" value="dev"/><br/>
<add key="TopicDomain" value="WDNCF"/><br/>
<add key="TopicType" value="dev"/><br/>
<add key="ReplyTimeoutSeconds" value="30"/><br/>
<add key="StorageType" value="XML"/><br/>
<!-- Or "Database"--><br/>
<add key="ErrorsFile" value="ErrorConfig.xml"/><br/>
<add key="ToolID" value="RUCVD-03"/><br/>
<add key="ErrorsFilePath" value=".\local\config\"/><br/>
</EMHelper><br/>
<!-- END Error Helper config Settings--><br/>
<log4net><br/>
<appender name="DebugFileAppender" type="log4net.Appender.RollingFileAppender <br/>
<file value="locallogsApplnTrace.log"/><br/>
<threshold value="INFO"/><br/>
<appendToFile value="true"/><br/>
<rollingStyle value="Date"/><br/>
<datePattern value="yyyyMMdd"/><br/>
<layout type="log4net.Layout.PatternLayout <br/>
<param name="ConversionPattern" value="%d [%5p] - (%file:%line) %m%n"/><br/>
</layout><br/>
</appender><br/>
<logger name="ApplnLogger <br/>
<appender-ref ref="DebugFileAppender"/><br/>
</logger><br/>
<appender name="ErrorFileAppender" type="log4net.Appender.RollingFileAppender <br/>
<file value="locallogsError.log"/><br/>
<threshold value="DEBUG" /><br/>
<appendToFile value="true" /><br/>
<maximumFileSize value="100MB" /><br/>
<maxSizeRollBackups value="10" /><br/>
<datePattern value="yyyyMMdd" /><br/>
<layout type="log4net.Layout.PatternLayout <br/>
<param name="ConversionPattern" value="%d [%5p] - %m%n" /><br/>
</layout><br/>
</appender><br/>
<logger name="ErrorLogger <br/>
<appender-ref ref="ErrorFileAppender"/><br/>
</logger><br/>
</log4net><br/>
<!--<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>--><br/>
</configuration>
i need to confirm whether under ,log4net> section, whether <logger name="ErrorLogger has been defined.
I have following code, but does not seem to work.
private void button_GetLogFileSetting_Click(object sender, EventArgs e)<br/>
{<br/>
// Get the App.Config file path<br/>
// Pass it to function that grabs the log4net section<br/>
// check whether ErrorLog element exists<br/>
bool log4netSectionExists = false;<br/>
bool ErrorLoggerExists = false;
try<br/>
{<br/>
System.Configuration.Configuration config =<br/>
ConfigurationManager.OpenExeConfiguration(<br/>
ConfigurationUserLevel.None);
<br/>
ConfigurationSectionCollection sections =<br/>
config.Sections;
foreach (string key in sections.Keys)<br/>
{<br/>
if (key == "log4net")<br/>
{<br/>
Label_ResultsMessage.Text += string.Format("Key value: {0}", key);<br/>
log4netSectionExists = true;<br/>
}<br/>
}
if (log4netSectionExists)<br/>
{<br/>
// check whether ErrorLog element exists<br/>
try<br/>
{<br/>
// use config.FilePath<br/>
try<br/>
{<br/>
XElement elLog4net = XElement.Load(config.FilePath);
IEnumerable<XElement> errorLogger =<br/>
from el in elLog4net.Elements("logger")<br/>
where (string)el.Attribute("name") == "ErrorLogger"
//ApplnLogger<br/>
select el;
if (errorLogger != null) {<br/>
foreach (XElement el in errorLogger)<br/>
{<br/>
ErrorLoggerExists = true;<br/>
}<br/>
}
if (ErrorLoggerExists == true)<br/>
{
Label_ResultsMessage.Text += "nFound ErrorLogger!";<br/>
}<br/>
else { Label_ResultsMessage.Text += "nErrorLogger NOT FOUND!"; }<br/>
}<br/>
catch (Exception Ex)<br/>
{<br/>
throw;<br/>
}
}<br/>
catch (ConfigurationErrorsException err)<br/>
{<br/>
Console.WriteLine(err.ToString());<br/>
}
}<br/>
}<br/>
catch (ConfigurationErrorsException err)<br/>
{<br/>
Console.WriteLine(err.ToString());<br/>
}
}
how can i correct it please?
Thank you. - Piyush <hr class="sig piyush varma
View the full article
i have following App.Config file:
<?xml version="1.0"?><br/>
<configuration><br/>
<configSections><br/>
<section name="RUCVD-03" type="System.Configuration.AppSettingsSection"/><br/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/><br/>
<section name="EventTraceHelper" type="System.Configuration.AppSettingsSection"/><br/>
<!-- Add this section if you need to change Errorhelper settings--><br/>
<section name="EMHelper" type="System.Configuration.AppSettingsSection"/><br/>
</configSections><br/>
<appSettings><br/>
<!--Device, or Entity running, NAN-15, Tango-11, OCD-02, or others--><br/>
<add key="DeviceName" value="RUCVD-03"/><br/>
</appSettings><br/>
<!-- START Error Helper config Settings OPTIONAL see Help for all params--><br/>
<EMHelper><br/>
<add key="DatabaseName" value="ERRORMANAGEMENT"/><br/>
<add key="DatabaseType" value="Development"/><br/>
<add key="TSDSystem" value="TEST"/><br/>
<add key="ConnectionType" value="dev"/><br/>
<add key="TopicDomain" value="WDNCF"/><br/>
<add key="TopicType" value="dev"/><br/>
<add key="ReplyTimeoutSeconds" value="30"/><br/>
<add key="StorageType" value="XML"/><br/>
<!-- Or "Database"--><br/>
<add key="ErrorsFile" value="ErrorConfig.xml"/><br/>
<add key="ToolID" value="RUCVD-03"/><br/>
<add key="ErrorsFilePath" value=".\local\config\"/><br/>
</EMHelper><br/>
<!-- END Error Helper config Settings--><br/>
<log4net><br/>
<appender name="DebugFileAppender" type="log4net.Appender.RollingFileAppender <br/>
<file value="locallogsApplnTrace.log"/><br/>
<threshold value="INFO"/><br/>
<appendToFile value="true"/><br/>
<rollingStyle value="Date"/><br/>
<datePattern value="yyyyMMdd"/><br/>
<layout type="log4net.Layout.PatternLayout <br/>
<param name="ConversionPattern" value="%d [%5p] - (%file:%line) %m%n"/><br/>
</layout><br/>
</appender><br/>
<logger name="ApplnLogger <br/>
<appender-ref ref="DebugFileAppender"/><br/>
</logger><br/>
<appender name="ErrorFileAppender" type="log4net.Appender.RollingFileAppender <br/>
<file value="locallogsError.log"/><br/>
<threshold value="DEBUG" /><br/>
<appendToFile value="true" /><br/>
<maximumFileSize value="100MB" /><br/>
<maxSizeRollBackups value="10" /><br/>
<datePattern value="yyyyMMdd" /><br/>
<layout type="log4net.Layout.PatternLayout <br/>
<param name="ConversionPattern" value="%d [%5p] - %m%n" /><br/>
</layout><br/>
</appender><br/>
<logger name="ErrorLogger <br/>
<appender-ref ref="ErrorFileAppender"/><br/>
</logger><br/>
</log4net><br/>
<!--<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>--><br/>
</configuration>
i need to confirm whether under ,log4net> section, whether <logger name="ErrorLogger has been defined.
I have following code, but does not seem to work.
private void button_GetLogFileSetting_Click(object sender, EventArgs e)<br/>
{<br/>
// Get the App.Config file path<br/>
// Pass it to function that grabs the log4net section<br/>
// check whether ErrorLog element exists<br/>
bool log4netSectionExists = false;<br/>
bool ErrorLoggerExists = false;
try<br/>
{<br/>
System.Configuration.Configuration config =<br/>
ConfigurationManager.OpenExeConfiguration(<br/>
ConfigurationUserLevel.None);
<br/>
ConfigurationSectionCollection sections =<br/>
config.Sections;
foreach (string key in sections.Keys)<br/>
{<br/>
if (key == "log4net")<br/>
{<br/>
Label_ResultsMessage.Text += string.Format("Key value: {0}", key);<br/>
log4netSectionExists = true;<br/>
}<br/>
}
if (log4netSectionExists)<br/>
{<br/>
// check whether ErrorLog element exists<br/>
try<br/>
{<br/>
// use config.FilePath<br/>
try<br/>
{<br/>
XElement elLog4net = XElement.Load(config.FilePath);
IEnumerable<XElement> errorLogger =<br/>
from el in elLog4net.Elements("logger")<br/>
where (string)el.Attribute("name") == "ErrorLogger"
//ApplnLogger<br/>
select el;
if (errorLogger != null) {<br/>
foreach (XElement el in errorLogger)<br/>
{<br/>
ErrorLoggerExists = true;<br/>
}<br/>
}
if (ErrorLoggerExists == true)<br/>
{
Label_ResultsMessage.Text += "nFound ErrorLogger!";<br/>
}<br/>
else { Label_ResultsMessage.Text += "nErrorLogger NOT FOUND!"; }<br/>
}<br/>
catch (Exception Ex)<br/>
{<br/>
throw;<br/>
}
}<br/>
catch (ConfigurationErrorsException err)<br/>
{<br/>
Console.WriteLine(err.ToString());<br/>
}
}<br/>
}<br/>
catch (ConfigurationErrorsException err)<br/>
{<br/>
Console.WriteLine(err.ToString());<br/>
}
}
how can i correct it please?
Thank you. - Piyush <hr class="sig piyush varma
View the full article