Archive

Archive for March, 2015

Creating a custom event log under Event Viewer to log server events


http://microsoft-techies.blogspot.com/2015/03/creating-custom-event-log-under-event.html

Advertisements
Categories: Uncategorized

System.Xml.XPath.XPathException has an invalid token


<?xml version="1.0" encoding="UTF-8" ?>
<uclassify xmlns="http://api.uclassify.com/1/server/ResponseSchema" version="1.01">
    <status id success="true" statusCode="2000"/>
    <readCalls>
        <classify id="Classify">
        <classification textCoverage="0.849057">
            <class className="negative" p="0.567908"/>
            <class className="positive" p="0.432092"/>
        </classification>
        </classify>
    </readCalls>
</uclassify>

Solution:
I was using "status id" , i changed to statusID, it solved my issue.

Categories: Uncategorized

Log4Net Example in C# Console Application

Categories: Uncategorized

System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize —> System.Configuration.ConfigurationErrorsException: Only one element allowed per config file and if present must be the first child of the root element.


Error:┬áSystem.Configuration.ConfigurationErrorsException: Configuration system failed to initialize —> System.Configuration.ConfigurationErrorsException: Only one <configSections> element allowed per config file and if present must be the first child of the root <configuration> element.

Solution:

Error app.config

——–

<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<appSettings>
<add key=”AA” value=”log4net.config” />
</appSettings>

<startup>
<supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.0″/>
</startup>

<!– <log4net configSource=”log4net.config” /> –>
<configSections>
<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net” />
</configSections>
<log4net>
<appender name=”RollingFileAppender” type=”log4net.Appender.RollingFileAppender”>
<File value=”File1.log” />
<AppendToFile value=”true” />
<rollingStyle value=”Composite” />
<maximumFileSize value=”200MB” />
<layout type=”log4net.Layout.PatternLayout”>
<ConversionPattern value=”%date %messge%newline”/>
</layout>
</appender>

<appender name=”LogFileAppender” type=”log4net.Appender.RollingFileAppender”>
<File value=”File2.log” />
<AppendToFile value=”true” />
<rollingStyle value=”Date” />
<maximumFileSize value=”100MB” />
<layout type=”log4net.Layout.PatternLayout”>
<ConversionPattern value=”%date %messge%newline”/>
</layout>

<filter type=”log4net.Filter.LevelRangeFilter”>
<acceptOnMatch value=”true” />
<levelMin value=”INFO” />
</filter>
<filter type=”log4net.Filter.LevelRangeFilter”>
<acceptOnMatch value=”true” />
<levelMin value=”FATAL” />
</filter>
</appender>

<appender name=”ColoredConsoleAppender” type=”log4net.Appender.ColoredConsoleAppender”>
<mapping>
<level value =”ERROR”/>
<foreColor value =”Red”/>
</mapping>

<mapping>
<level value =”WARN”/>
<foreColor value =”Yellow”/>
</mapping>
<layout type=”log4net.Layout.PatternLayout”>
<ConversionPattern value=”%date %messge%newline”/>
</layout>
</appender>

<root>
<level value=”ALL” />
<appender-ref ref=”LogFileAppender” />
<appender-ref ref=”RollingFileAppender” />
<appender-ref ref=”ColoredConsoleAppender” />
</root>

<logger name=”FileLogger” additivity=”false”>
<level value=”ALL” />
<appender-ref ref=”LogFileAppender” />
</logger>

<logger name = “ConsoleLogger” additivity=”false”>
<level value=”ALL” />
<appender-ref ref=”ColoredConsoleAppender” />
</logger>
</log4net>

</configuration>

Working App.config

——–

<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<!– <log4net configSource=”log4net.config” /> –>
<configSections>
<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net” />
</configSections>
<log4net>
<appender name=”RollingFileAppender” type=”log4net.Appender.RollingFileAppender”>
<File value=”File1.log” />
<AppendToFile value=”true” />
<rollingStyle value=”Composite” />
<maximumFileSize value=”200MB” />
<layout type=”log4net.Layout.PatternLayout”>
<ConversionPattern value=”%date %messge%newline”/>
</layout>
</appender>

<appender name=”LogFileAppender” type=”log4net.Appender.RollingFileAppender”>
<File value=”File2.log” />
<AppendToFile value=”true” />
<rollingStyle value=”Date” />
<maximumFileSize value=”100MB” />
<layout type=”log4net.Layout.PatternLayout”>
<ConversionPattern value=”%date %messge%newline”/>
</layout>

<filter type=”log4net.Filter.LevelRangeFilter”>
<acceptOnMatch value=”true” />
<levelMin value=”INFO” />
</filter>
<filter type=”log4net.Filter.LevelRangeFilter”>
<acceptOnMatch value=”true” />
<levelMin value=”FATAL” />
</filter>
</appender>

<appender name=”ColoredConsoleAppender” type=”log4net.Appender.ColoredConsoleAppender”>
<mapping>
<level value =”ERROR”/>
<foreColor value =”Red”/>
</mapping>

<mapping>
<level value =”WARN”/>
<foreColor value =”Yellow”/>
</mapping>
<layout type=”log4net.Layout.PatternLayout”>
<ConversionPattern value=”%date %messge%newline”/>
</layout>
</appender>

<root>
<level value=”ALL” />
<appender-ref ref=”LogFileAppender” />
<appender-ref ref=”RollingFileAppender” />
<appender-ref ref=”ColoredConsoleAppender” />
</root>

<logger name=”FileLogger” additivity=”false”>
<level value=”ALL” />
<appender-ref ref=”LogFileAppender” />
</logger>

<logger name = “ConsoleLogger” additivity=”false”>
<level value=”ALL” />
<appender-ref ref=”ColoredConsoleAppender” />
</logger>
</log4net>

<appSettings>
<add key=”AA” value=”log4net.config” />
</appSettings>

<startup>
<supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.0″/>
</startup>
</configuration>

C# code

string stra = ConfigurationManager.AppSettings[“AA”];

Categories: Uncategorized

Read XML C#

Categories: Uncategorized

Converting a console application to a dll in c#

Categories: Uncategorized

Reading and Writing CSV Files in C#

Categories: Uncategorized