473,569 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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" ?>

<configuratio n>

<!-- Register the section handler for the log4net section -->

<configSections >

<section name="log4net"
type="log4net.C onfig.Log4NetCo nfigurationSect ionHandler,log4 net" />

</configSections>

<appSettings>
</appSettings>

<!-- This section contains the log4net configuration settings -->

<log4net debug="true" >

<!-- Define some output appenders -->
<!-- Rolling file appender -->

<appender name="RollingLo gFileAppender"
type="log4net.A ppender.Rolling FileAppender,lo g4net">

<param name="File" value="Dataqueu eworker-Errlog.txt" />

<param name="AppendToF ile" value="true" />

<param name="MaxSizeRo llBackups" value="10" />

<param name="MaximumFi leSize" value="1000KB" />

<param name="StaticLog FileName" value="true" />

<layout type="log4net.L ayout.PatternLa yout,log4net">

<param name="Header" value="[Header]\r\n"/>

<param name="Footer" value="[Footer]\r\n"/>

<!-- <param name="Conversio nPattern" value="%d [%t] %-5p %c [%x] - %m%n"
/> -->

<!-- <param name="Conversio nPattern" value="%-5p %d [%t] %m%n" /> -->

<param name="Conversio nPattern" value="%-5p %d %m%n" />

</layout>

</appender>

<!-- File appender -->

<appender name="LogFileAp pender"
type="log4net.A ppender.FileApp ender,log4net" >

<param name="File" value="DAtaqueu eworker-log.txt" />

<param name="AppendToF ile" value="true" />

<layout type="log4net.L ayout.PatternLa yout,log4net">
<param name="Conversio nPattern" value="%-5p %d [%t] %m%n" />

<!--

<param name="Conversio nPattern"

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{resource}', '%X{entitlement }
','%X{arguments }','%X{message} ')" />

-->

</layout>

</appender>
<!-- ConsoleAppender -->

<appender name="ConsoleAp pender"
type="log4net.A ppender.Console Appender,log4ne t" >

<layout type="log4net.L ayout.PatternLa yout,log4net">

<!--

<param name="Conversio nPattern" value="%d [%t] %-5p %c [%x]
&lt;%X{auth}&gt ; - %m%n" />

-->

<param name="Conversio nPattern"

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{resource}', '%X{entitlement }
','%X{arguments }','%X{message} ')" />

</layout>

</appender>

<!-- ADONetAppender -->

<appender name="ADONetApp ender"
type="log4net.A ppender.ADONetA ppender,log4net " >

<param name="Connectio nString"

value="Server=l ocalhost;Initia l Catalog=TesTest ;user id=sa;password= ;Connect
Timeout=5" />

<layout type="log4net.L ayout.PatternLa yout,log4net">

<!-- <param name="Conversio nPattern" 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="Conversio nPattern"

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="RollingLog FileAppender" />

<appender-ref ref="LogFileApp ender" />

</root>

<!-- Specify the priority for some specific categories -->

<category name="TesPrivil egeLog">

<priority value="INFO" />

<appender-ref ref="ADONetAppe nder" />

</category>
</log4net>


</configuration>


Apr 10 '06 #1
2 5143
Hi Vikram,

following is the contents of my App.Config -

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<section name="log4net"
type="log4net.C onfig.Log4NetCo nfigurationSect ionHandler, log4net" />
</configSections>
<log4net debug="false">
<appender name="LogFileAp pender"
type="log4net.A ppender.FileApp ender,log4net" >
<param name="File" value="c:\\Log4 NetConsole.txt" />
<param name="AppendToF ile" value="true" />
<layout type="log4net.L ayout.PatternLa yout,log4net">
<param name="Conversio nPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> -
%m%n" />
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="LogFileApp ender" />
</root>
<category name="Test"><pr iority value="ALL" /></category>
</log4net>
</configuration>

And my class file contents are -

using System;
using log4net;

namespace Log4NetConsoleA pp
{

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

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

}

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" ?>

<configuratio n>

<!-- Register the section handler for the log4net section -->

<configSections >

<section name="log4net"
type="log4net.C onfig.Log4NetCo nfigurationSect ionHandler,log4 net" />

</configSections>

<appSettings>
</appSettings>

<!-- This section contains the log4net configuration settings -->

<log4net debug="true" >

<!-- Define some output appenders -->
<!-- Rolling file appender -->

<appender name="RollingLo gFileAppender"
type="log4net.A ppender.Rolling FileAppender,lo g4net">

<param name="File" value="Dataqueu eworker-Errlog.txt" />

<param name="AppendToF ile" value="true" />

<param name="MaxSizeRo llBackups" value="10" />

<param name="MaximumFi leSize" value="1000KB" />

<param name="StaticLog FileName" value="true" />

<layout type="log4net.L ayout.PatternLa yout,log4net">

<param name="Header" value="[Header]\r\n"/>

<param name="Footer" value="[Footer]\r\n"/>

<!-- <param name="Conversio nPattern" value="%d [%t] %-5p %c [%x] - %m%n"
/> -->

<!-- <param name="Conversio nPattern" value="%-5p %d [%t] %m%n" /> -->

<param name="Conversio nPattern" value="%-5p %d %m%n" />

</layout>

</appender>

<!-- File appender -->

<appender name="LogFileAp pender"
type="log4net.A ppender.FileApp ender,log4net" >

<param name="File" value="DAtaqueu eworker-log.txt" />

<param name="AppendToF ile" value="true" />

<layout type="log4net.L ayout.PatternLa yout,log4net">
<param name="Conversio nPattern" value="%-5p %d [%t] %m%n" />

<!--

<param name="Conversio nPattern"

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="ConsoleAp pender"
type="log4net.A ppender.Console Appender,log4ne t" >

<layout type="log4net.L ayout.PatternLa yout,log4net">

<!--

<param name="Conversio nPattern" value="%d [%t] %-5p %c [%x]
<%X{auth}> - %m%n" />

-->

<param name="Conversio nPattern"

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="ADONetApp ender"
type="log4net.A ppender.ADONetA ppender,log4net " >

<param name="Connectio nString"

value="Server=l ocalhost;Initia l Catalog=TesTest ;user id=sa;password= ;Connect
Timeout=5" />

<layout type="log4net.L ayout.PatternLa yout,log4net">

<!-- <param name="Conversio nPattern" 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="Conversio nPattern"

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="RollingLog FileAppender" />

<appender-ref ref="LogFileApp ender" />

</root>

<!-- Specify the priority for some specific categories -->

<category name="TesPrivil egeLog">

<priority value="INFO" />

<appender-ref ref="ADONetAppe nder" />

</category>
</log4net>


</configuration>


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

"Kaustav" <Ka*****@discus sions.microsoft .com> wrote in message
news:91******** *************** ***********@mic rosoft.com...
Hi Vikram,

following is the contents of my App.Config -

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<section name="log4net"
type="log4net.C onfig.Log4NetCo nfigurationSect ionHandler, log4net" />
</configSections>
<log4net debug="false">
<appender name="LogFileAp pender"
type="log4net.A ppender.FileApp ender,log4net" >
<param name="File" value="c:\\Log4 NetConsole.txt" />
<param name="AppendToF ile" value="true" />
<layout type="log4net.L ayout.PatternLa yout,log4net">
<param name="Conversio nPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> -
%m%n" />
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="LogFileApp ender" />
</root>
<category name="Test"><pr iority value="ALL" /></category>
</log4net>
</configuration>

And my class file contents are -

using System;
using log4net;

namespace Log4NetConsoleA pp
{

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

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

}

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" ?>

<configuratio n>

<!-- Register the section handler for the log4net section -->

<configSections >

<section name="log4net"
type="log4net.C onfig.Log4NetCo nfigurationSect ionHandler,log4 net" />

</configSections>

<appSettings>
</appSettings>

<!-- This section contains the log4net configuration settings -->

<log4net debug="true" >

<!-- Define some output appenders -->
<!-- Rolling file appender -->

<appender name="RollingLo gFileAppender"
type="log4net.A ppender.Rolling FileAppender,lo g4net">

<param name="File" value="Dataqueu eworker-Errlog.txt" />

<param name="AppendToF ile" value="true" />

<param name="MaxSizeRo llBackups" value="10" />

<param name="MaximumFi leSize" value="1000KB" />

<param name="StaticLog FileName" value="true" />

<layout type="log4net.L ayout.PatternLa yout,log4net">

<param name="Header" value="[Header]\r\n"/>

<param name="Footer" value="[Footer]\r\n"/>

<!-- <param name="Conversio nPattern" value="%d [%t] %-5p %c [%x] - %m%n"
/> -->

<!-- <param name="Conversio nPattern" value="%-5p %d [%t] %m%n" /> -->

<param name="Conversio nPattern" value="%-5p %d %m%n" />

</layout>

</appender>

<!-- File appender -->

<appender name="LogFileAp pender"
type="log4net.A ppender.FileApp ender,log4net" >

<param name="File" value="DAtaqueu eworker-log.txt" />

<param name="AppendToF ile" value="true" />

<layout type="log4net.L ayout.PatternLa yout,log4net">
<param name="Conversio nPattern" value="%-5p %d [%t] %m%n" />

<!--

<param name="Conversio nPattern"

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="ConsoleAp pender"
type="log4net.A ppender.Console Appender,log4ne t" >

<layout type="log4net.L ayout.PatternLa yout,log4net">

<!--

<param name="Conversio nPattern" value="%d [%t] %-5p %c [%x]
<%X{auth}> - %m%n" />

-->

<param name="Conversio nPattern"

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="ADONetApp ender"
type="log4net.A ppender.ADONetA ppender,log4net " >

<param name="Connectio nString"

value="Server=l ocalhost;Initia l Catalog=TesTest ;user id=sa;password= ;Connect Timeout=5" />

<layout type="log4net.L ayout.PatternLa yout,log4net">

<!-- <param name="Conversio nPattern" 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="Conversio nPattern"

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="RollingLog FileAppender" />

<appender-ref ref="LogFileApp ender" />

</root>

<!-- Specify the priority for some specific categories -->

<category name="TesPrivil egeLog">

<priority value="INFO" />

<appender-ref ref="ADONetAppe nder" />

</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
732
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 given in the log4net config file. Please help
0
1717
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" type="System.Configuration.IgnoreSectionHandler" /> </configSections>
0
466
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 some custom loggers (run-time) and (i think) i've been able to add new custom loggers to the root logger of the repository. i've also added one...
4
2198
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 Gawel
6
8098
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 create more loggers (subloggers). This is nice since I can use just one configuration file to control the behaviour of all the loggers within my app....
2
2091
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 FileAppender, as well as the RollingFileAppender, but both don't work exactly the way I'd like them to.
1
5161
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. And my application has a different AppDomain as it is a customization of another COM based application written in VB.NET. I have tried with...
2
20018
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 supplied with the source are anything but helpful. Thanks for any input. -fd
4
2239
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
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.