V
Vikram
I am using log4net in a vb.net console application. But its not working. I
have added congif setting in app.config file also
No error is generated but app. does not write to log file.
app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- Register the section handler for the log4net section -->
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<appSettings>
</appSettings>
<!-- This section contains the log4net configuration settings -->
<log4net debug="true" >
<!-- Define some output appenders -->
<!-- Rolling file appender -->
<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value="Dataqueueworker-Errlog.txt" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="10" />
<param name="MaximumFileSize" value="1000KB" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="Header" value="[Header]\r\n"/>
<param name="Footer" value="[Footer]\r\n"/>
<!-- <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"
/> -->
<!-- <param name="ConversionPattern" value="%-5p %d [%t] %m%n" /> -->
<param name="ConversionPattern" value="%-5p %d %m%n" />
</layout>
</appender>
<!-- File appender -->
<appender name="LogFileAppender"
type="log4net.Appender.FileAppender,log4net" >
<param name="File" value="DAtaqueueworker-log.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%-5p %d [%t] %m%n" />
<!--
<param name="ConversionPattern"
value="%d [%t] %-5p %c[%x] <%X{auth}> - %m%n ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%X{result}','%X{principal}','%X{resource}','%X{entitlement}
','%X{arguments}','%X{message}')" />
-->
</layout>
</appender>
<!-- ConsoleAppender -->
<appender name="ConsoleAppender"
type="log4net.Appender.ConsoleAppender,log4net" >
<layout type="log4net.Layout.PatternLayout,log4net">
<!--
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x]
<%X{auth}> - %m%n" />
-->
<param name="ConversionPattern"
value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%X{result}','%X{principal}','%X{resource}','%X{entitlement}
','%X{arguments}','%X{message}')" />
</layout>
</appender>
<!-- ADONetAppender -->
<appender name="ADONetAppender"
type="log4net.Appender.ADONetAppender,log4net" >
<param name="ConnectionString"
value="Server=localhost;Initial Catalog=TesTest;user id=sa;password=;Connect
Timeout=5" />
<layout type="log4net.Layout.PatternLayout,log4net">
<!-- <param name="ConversionPattern" value="INSERT INTO Log (Created,
Thread, Priority, Logger, Message, Context) VALUES ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%p','%c','%m','%x')" /> -->
<param name="ConversionPattern"
value="INSERT INTO Log (created, thread, result, principal, resource,
entitlement, arguments, message) VALUES ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%X{result}','%X{principal}','%X{resource}','%X{entitlement}
','%X{arguments}','%X{message}')" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default
priority -->
<root>
<priority value="INFO" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="LogFileAppender" />
</root>
<!-- Specify the priority for some specific categories -->
<category name="TesPrivilegeLog">
<priority value="INFO" />
<appender-ref ref="ADONetAppender" />
</category>
</log4net>
</configuration>
have added congif setting in app.config file also
No error is generated but app. does not write to log file.
app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- Register the section handler for the log4net section -->
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<appSettings>
</appSettings>
<!-- This section contains the log4net configuration settings -->
<log4net debug="true" >
<!-- Define some output appenders -->
<!-- Rolling file appender -->
<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value="Dataqueueworker-Errlog.txt" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="10" />
<param name="MaximumFileSize" value="1000KB" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="Header" value="[Header]\r\n"/>
<param name="Footer" value="[Footer]\r\n"/>
<!-- <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"
/> -->
<!-- <param name="ConversionPattern" value="%-5p %d [%t] %m%n" /> -->
<param name="ConversionPattern" value="%-5p %d %m%n" />
</layout>
</appender>
<!-- File appender -->
<appender name="LogFileAppender"
type="log4net.Appender.FileAppender,log4net" >
<param name="File" value="DAtaqueueworker-log.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%-5p %d [%t] %m%n" />
<!--
<param name="ConversionPattern"
value="%d [%t] %-5p %c[%x] <%X{auth}> - %m%n ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%X{result}','%X{principal}','%X{resource}','%X{entitlement}
','%X{arguments}','%X{message}')" />
-->
</layout>
</appender>
<!-- ConsoleAppender -->
<appender name="ConsoleAppender"
type="log4net.Appender.ConsoleAppender,log4net" >
<layout type="log4net.Layout.PatternLayout,log4net">
<!--
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x]
<%X{auth}> - %m%n" />
-->
<param name="ConversionPattern"
value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%X{result}','%X{principal}','%X{resource}','%X{entitlement}
','%X{arguments}','%X{message}')" />
</layout>
</appender>
<!-- ADONetAppender -->
<appender name="ADONetAppender"
type="log4net.Appender.ADONetAppender,log4net" >
<param name="ConnectionString"
value="Server=localhost;Initial Catalog=TesTest;user id=sa;password=;Connect
Timeout=5" />
<layout type="log4net.Layout.PatternLayout,log4net">
<!-- <param name="ConversionPattern" value="INSERT INTO Log (Created,
Thread, Priority, Logger, Message, Context) VALUES ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%p','%c','%m','%x')" /> -->
<param name="ConversionPattern"
value="INSERT INTO Log (created, thread, result, principal, resource,
entitlement, arguments, message) VALUES ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%X{result}','%X{principal}','%X{resource}','%X{entitlement}
','%X{arguments}','%X{message}')" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default
priority -->
<root>
<priority value="INFO" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="LogFileAppender" />
</root>
<!-- Specify the priority for some specific categories -->
<category name="TesPrivilegeLog">
<priority value="INFO" />
<appender-ref ref="ADONetAppender" />
</category>
</log4net>
</configuration>