473,216 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

log4net in console app

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.Log4NetConfigurationSectionHa ndler,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] &lt;%X{auth}&gt; - %m%n ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%X{result}','%X{principal}','%X{r esource}','%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]
&lt;%X{auth}&gt; - %m%n" />

-->

<param name="ConversionPattern"

value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n ('%d{dd-MMM-yyyy
HH:mm:ss}','%t','%X{result}','%X{principal}','%X{r esource}','%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{r esource}','%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>


Apr 10 '06 #1
2 5119
Hi Vikram,

following is the contents of my App.Config -

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHa ndler, log4net" />
</configSections>
<log4net debug="false">
<appender name="LogFileAppender"
type="log4net.Appender.FileAppender,log4net" >
<param name="File" value="c:\\Log4NetConsole.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> -
%m%n" />
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
<category name="Test"><priority value="ALL" /></category>
</log4net>
</configuration>

And my class file contents are -

using System;
using log4net;

namespace Log4NetConsoleApp
{

class Class1
{
private ILog logger = LogManager.GetLogger("Test");

[STAThread]
static void Main(string[] args)
{
log4net.Config.DOMConfigurator.Configure();
Class1 obj = new Class1();
obj.log("Testing");

}

private void log(string str)
{
logger.Info(str);
}
}
}

This works for me.

"Vikram" wrote:
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.Log4NetConfigurationSectionHa ndler,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{r esource}','%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{r esource}','%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{r esource}','%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>


Apr 10 '06 #2
Thanks Kaustav.
I was missing "log4net.Config.DOMConfigurator.Configure(); "
statement.

"Kaustav" <Ka*****@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
Hi Vikram,

following is the contents of my App.Config -

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHa ndler, log4net" />
</configSections>
<log4net debug="false">
<appender name="LogFileAppender"
type="log4net.Appender.FileAppender,log4net" >
<param name="File" value="c:\\Log4NetConsole.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> -
%m%n" />
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
<category name="Test"><priority value="ALL" /></category>
</log4net>
</configuration>

And my class file contents are -

using System;
using log4net;

namespace Log4NetConsoleApp
{

class Class1
{
private ILog logger = LogManager.GetLogger("Test");

[STAThread]
static void Main(string[] args)
{
log4net.Config.DOMConfigurator.Configure();
Class1 obj = new Class1();
obj.log("Testing");

}

private void log(string str)
{
logger.Info(str);
}
}
}

This works for me.

"Vikram" wrote:
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.Log4NetConfigurationSectionHa ndler,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{r esource}','%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{r esource}','%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{r esource}','%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>


Apr 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: SK | last post by:
Hi, I am using log4net in my c# application.Want to know how to customize the log output format. I know that it can be done using LayoutSkeleton class,but dont know what other parameters to be...
0
by: anonieko | last post by:
Add a reference to log4net.dll 1: In the APP.CONFIG write the following: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="log4net"...
0
by: Joneleth | last post by:
Hi, anyone can help with log4net? i'm not sure i understand log4net object model properly... i'm trying to configure log4net programmatically, in order to assign different custom appenders to...
4
by: Gawel | last post by:
hajo, can someone send me an example how to use above pattern in asp.net applicaiton? I can not figure out how to do it. I get no exceptions, simply no logging occures. Thanks for any info ...
6
by: Mr Flibble | last post by:
Hi all, I've decided to use log4net for my logging/tracing. In the example on the site it shows using main() to setup the root logger and then using the LogManager within your classes to...
2
by: Marc Scheuner | last post by:
Folks, I'd really like to use log4net for our error logging, but I'm having two problems: 1) For certain cases, I'd like to log error and messages to text files. I tried both the regular...
1
by: chidam.chidam | last post by:
Hi all, I would like to implement log4net for logging my application. First let me describe in short about the application. I have a solution with two exe file outputs and several dll assemblies....
2
by: forest demon | last post by:
I need to be able to create an appender to direct output to a MessageBox. The API does not have a MessageBox appender like nLog does. What would be the easiest way to do this. The examples...
4
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; When my ASP.NET app is running on IIS, where does the Console.Out.WriteLine("hi there"); output go? -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.