Michael Flanakin's Web Log

Comments and complaints on software and technology in general

  Home  |   Contact  |   Syndication    |   Login
  159 Posts | 18 Stories | 89 Comments | 530 Trackbacks

News

This weblog is no longer being maintained. For the latest, check out www.michaelflanakin.com!

Article Categories

Archives

Post Categories

Image Galleries

Miscellaneous

Yeah, that's kind of harsh, but it's how I feel after spending the past 4 hours trying to get the ADONetAppender to work.

First off, has anyone used this thing before? There are hardly any useful examples available - both with log4net and accessible via Google. Second, who wrote the documentation for this tool? Maybe I'm spoiled after spending a lot of time working on advanced NAnt scripts, but the log4net documentation is worthless. I shouldn't have to read an 8 page, 3000 word document to get an intro to the tool. That's ridiculous. All I want is a “Getting Started” link that will walk me through setting this stupid thing up. Is that too much to ask for? I know a few people who've used log4j and they were saying how easy it was to setup. I don't know what happened in the conversion, but this is pitiful.

Anyway, I can't even tell if the thing is on or what. I setup the config file based on what was provided in the help docs and that doesn't seem to help at all. I tried specifying the wrong config section handler, but that didn't break anything, so I'm guessing that I have something setup wrong.

Unless someone severely works on the crap4docs that come with this tool, I don't see how anyone can get this to work. If someone knows of a good resource that might help, please let me know. I really don't want to sign up on the email list to figure out this one small issue and probably get tons more email that I don't care about.

posted on Monday, August 30, 2004 4:51 PM

Feedback

# re: Log4Net is Crap4Crap 8/31/2004 1:12 PM scott
I doubt you'd get tons of email if you ask on the list, you may just get the developers to answer the question though.

Have you tried the udpappender? If you use that, you can use Chainsaw to view the events from log4net.

Here's the link to Chainsaw:
http://logging.apache.org/log4j/docs/chainsaw.html

Scott

# re: Log4Net is Crap4Crap 9/4/2004 11:17 AM Rich Denis
I have and still use log4net and even have it working with the ADONetAppender. Please feel free to join the users-list since that is where you can get all your questions answered. The authors support the list and can give you advice on what you may or may not be doing. When you post, make sure you include your config file and how you are initializing the log4net system (code vs attributes]

Hope to see you there. log4net is really powerful.

# re: Log4Net is Crap4Crap 9/10/2004 12:47 PM Joe
One thing that I have found that will frustrate you beyond belief if you don't know about it is the assembly level attribute needed for log4net's DomConfiguration component to read the app.config.

log4net watches the app.config file for updates, therefore to have it all work you must add this attribute to your assemblyinfo.cs file:

[assembly: log4net.Config.DOMConfigurator(Watch=true)]

Then if you get something simple like UDPAppender working, you now at least log4net is setup correctly in your application.

I am currently implementing the ADONetAppender for the first time, and have not found it too troublesome. One thing that I have noticed is that the records seem to be transactional. My table doesn't get updated until I close the application (which subsequentially closes the database connection).

I stumbled upon this blog looking for an answer on how to get it to update live.

I will update if I find the answer.

Joe.
email@josephdecarlo.com

# re: Log4Net is Crap4Crap 9/10/2004 3:45 PM Joe
Found the answer to my problem... The ADONetAppender is a buffered appender. Because of this, it does not write to the database until the amount of log entries exceeds the buffer size set in the <param name="BufferSize" value="100"/> entry of the app.config.


Just another note on getting log4net working, try using the consoleappender as it requires no other applications to see the results (just a thought)

Joe.

# architect 10/11/2004 5:49 PM Sasha
documentation for log4net is awful, for net 1.1 samples are missing - instead you can find js files with cs content ("C:\Program Files\Microsoft Application Blocks for .NET\log4net\examples\net\1.1\Domain\SharedModule\js\src\Math.js"), build files do not work, it is ugly, maybe it is easy to use - who know? i am trying to log into event log and have no idea - is it assembly problem, or config problem or else... i am administrator on my machine and log only produces console ouputs. it looks like it easier to write custom logger rather than figure what should be done. If it is "easy to use" and it "works" for some people - why it is impossible to find simple zip with running sample???

# architect 10/11/2004 6:36 PM Sasha
i have to apologize for the previous email. despite of lacking instructions it is doable (i made few examples, but not db logging)
the keys are (this describes how to use not config but log4net file):
1. create xml file in app location similar to
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="true">
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<!--
The following example shows how to configure the EventLogAppender to log to the
Application event log on the local machine using the event Source of the AppDomain.FriendlyName.
-->
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>

<!--
The following example shows how to configure the FileAppender to write messages to a file. The file specified is log-file.txt. The file will be appended to rather than overwritten each time the logging process starts.
-->
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="log-file.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>

<!--
The following example shows how to configure the ColoredConsoleAppender to log messages to the console.
By default the messages are sent to the console standard output stream. This example shows how to highlight error messages.
-->
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<mapping>
<level value="ERROR" />
<foreColor value="White" />
<backColor value="Red, HighIntensity" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>

<root>
<!-- you can try this instead of ColoredConsoleAppender, adjust level value if needed
<appender-ref ref="FileAppender" />
<appender-ref ref="EventLogAppender" />
-->

<level value="ALL" />
<appender-ref ref="ColoredConsoleAppender" />

</root>
</log4net>

2. in your class put
using log4net;

/// to make available console output, make your app Console Application (change project properties)
// Configure logging for this assembly using the '....exe.log4net' file
[assembly: log4net.Config.DOMConfigurator(ConfigFileExtension="log4net", Watch=true)]

this will instruct to look for log4net file
3. put in the beginning of your class (my class was Form1)
private static readonly ILog log = LogManager.GetLogger(typeof(Form1));

4. actual loggin will look like (i put this code onto button event
)
if (log.IsDebugEnabled)
log.Debug("debugging ");

log.Error("error test 1" );

5. to try different logs you can change appender-ref ref attribute in root note of your log4net file.

6. to see colored logging change your app output type to console output in project properties.

# re: Log4Net is Crap4Crap 10/20/2004 3:13 PM Michael Hall
You seriously helped me cut through the chaff. I was having a heck of a time with the log4net documentation, but your samples worked for me!

Thanks!

# re: Log4Net is Crap4Crap 10/21/2004 10:36 PM samitha
I'm getting the following messages
log4net:ERROR No appender named [LogFileAppender] could be found.
log4net: Appender named [LogFileAppender] not found.
log4net:ERROR No appenders could be found for category (Com.SriLogic.Qsurv.QBuilder.Gui.MainForm).
log4net:ERROR Please initialize the log4net system properly.
here is the config file
/**/
<?xml version="1.0" encoding="utf-8" ?>
<!-- .NET application configuration file

This file must have the exact same name as your application with
.config appended to it. For example if your application is testApp.exe
then the config file must be testApp.exe.config it mut also be in the
same directory as the application. -->
<configuration>
<!-- Register the section handler for the log4net section -->
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<startup>
<supportedRuntime version="V1.1.4322"/>
</startup>
<appSettings>
<add key="SerialQuestionID" value="1"/>
<add key="log4net.Internal.Debug" value="true"/>

</appSettings>
<!-- This section contains the log4net configuration settings -->
<log4net debug="true">

<logger name="Com.SriLogic.Qsurv.QBuilder.Gui.MainForm">
<level value="INFO"/>
<appender-ref ref="LogFileAppender" />
</logger>
<!-- Define some output appenders -->
<appender name="LogFileAppender" type="log4net.Appender.FileAppender,log4net">
<!--param name="File" value="c:\\error-log.txt" /-->
<file value="C:\\error-log.txt" />
<param name="AppendToFile" value="true" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<priority value="INFO" />
<appender-ref ref="LogFileAppender" />
</root>
<!-- Specify the priority for some specific categories -->
<category name="Com.SriLogic.Qsurv">
<priority value="INFO" />
<appender-ref ref="LogFileAppender" />
</category>
</log4net>
</configuration>

/**/

how can I fix this?

# re: Log4Net is Crap4Crap 10/25/2004 3:12 PM mirza
thanks a lot man. these 6 steps is all i was looking for.


# re: Log4Net is Crap4Crap 10/29/2004 9:44 AM Vijay
Hi,
I tried adding the [assembly: log4net.Config.DOMConfigurator(Watch=true)] to the assebly and using the log4net reference , however an error is throw stating it is not an attribute of the assembly , how do i resolve this??

# re: Log4Net is Crap4Crap 10/30/2004 11:32 AM Joseph DeCarlo
RE: How can I fix this?

I am a little confused on your app.config implementation's purpose. You specify that the root should have the LogFileAppender and you also specify a unique logger, but it also just uses the same appender. What's the purpose of your logger?

At any rate, I think the root of your error is that the logger element is declared above your appender definition. I have never seen it this way, so my guess is, that is what is causing your exception.

However, I would also consider removing the logger element all together as it has no impact with your current configuration. The only time you need to specify logger elements is if you have specific ILog's that need to log differently than the rest of the application.

It is also important not to confuse a logger element's bindings. It is bound to an ILog instance that has the name as the logger's name attribute value. Most people instantiate an ILog by using the GetLogger(typeof(classname)). However, you can also just put a string in there. The Logger element in the app.config is bound to an instance of an ILog not a class. (FYI).

# re: Log4Net is Crap4Crap 10/29/2004 9:44 AM Vijay 10/31/2004 6:55 AM Joseph DeCarlo
RE: DOMConfigurator Attribute problem.

Your syntax appears to be correct. Where are you adding this assembly attribute? You should be adding it to the AssemblyInfo.cs file.


# Try this assembly method. 11/1/2004 9:29 PM Bill
We should form a "I survived log4net" group :)....

Here how I've added my assembly item. I did NOT add it to the AssemblyInfo.cs directly. My app is a console app and this is added to the file that has the main method.

This is the VERY first line in the file.
[assembly:log4net.Config.DOMConfigurator(ConfigFile="Logging", ConfigFileExtension="config",Watch=false)]

My log4net config file is called Logging.config as is located in the same folder as the executable... (in this case in the bin\debug folder)

One thing that caught me was the levels. To test, write ALL levels to the appender like so.

log.Info("Info");
log.Debug("Debug");
log.Warn("Warn");
log.Fatal("Fatal");
log.Error("Error");

If one shows up, you've at least got the framework working.

By the way, this was the ONLY way I was able to the the file to load..

And why we're all venting... Whats up with the zero documentation on the Conversion patterns???





# re: Log4Net is Crap4Crap 11/2/2004 11:45 AM Dru Sellers
<quote>
And why we're all venting... Whats up with the zero documentation on the Conversion patterns???
</quote>

No Joke - But I did find this
http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html

%d - Date/Time
%t - Thread Name
%p - Priority
%c - Category or Type that reported the object
%x - Content you logged NDC style
%m - Application Info?
%n - New Line

# re: Log4Net is Crap4Crap 11/7/2004 5:26 PM Jonathan
How do you create Log4Net appender yourself? I need to create one for ETW (Event Tracing for Windows) and there doesn't seem to any information on it in the docs.
Anybody tried to create such appender before, by the way?

# re: Log4Net is Crap4Crap 11/9/2004 12:57 PM Code Monkey
yah I cant get it to work in the AssemblyInfo.cs file either. Complains that its not an attribute class. Glad the worthless examples ive read explain it really well. Ive tried to copy the source for for nAnt wich uses log4net but nAnt doesnt build using visual studio ... so I cant really go by what it does. Anyone else got any ideas? If log4net is suppose to be simplar to use then the Microsoft logging access block, that has got to really suck....

# re: Log4Net is Crap4Crap 11/9/2004 1:18 PM Code Monkey
Looks like my problem might be I was trying to use the non-beta version 1.1.1.1 instead of the 1.2 which all of the examples im guessing have been using. Looking at the dates of the builds, it seems like they may have quit working on log4net?

# re: Log4Net is Crap4Crap 11/9/2004 2:01 PM Code Monkey
Problem #1 - [assembly: log4net.Config.DOMConfigurator(Watch=true)] did not work using log4net 1.1.1.1 .. works with 1.2 beta 8 though.
2nd problem I was having , sort of still am, is that its trying to look for my config file in the compile directory, which doesnt get put there when you compile. Looks like I need to figure that one out yet

# re: Log4Net is Crap4Crap 11/15/2004 1:42 PM Zak
If you're using Visual Studio, name your config file App.config and it will automatically be copied into the compile directory (and renamed to Whatever.exe.config) for you.


# re: Log4Net is Crap4Crap 11/16/2004 2:37 PM Dion
Michael, I've also had some troubles with the ADONetAppender, but after changing the configuration, it all works fine.

Most important is to put BufferSize to "1" to see results in the database after a single Log (<bufferSize value="1" />).

Also, please check your connectionstring again (you won't notice when it's wrong, because the ADONetAppender just will quit silently).

Finally, the @thread, @log_level, @logger and @message parameters seem to use the wrong conversionPatterns.

Please use these paramters in your config:

<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%t" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%p" />
</layout>
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%c" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%m" />
</layout>
</parameter>
<parameter>
<parameterName value="@exception" />
<dbType value="String" />
<size value="2000" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>


# re: Log4Net is Crap4Crap 11/29/2004 7:29 AM robert
hello,

I want to use the DataAppender of log4net to save log-information in a
Database of my Smart Device Application.

My dataTable looks as follows:

Date nvarchar 50
UserName nvarchar 50
ClassName nvarchar 50
Method nvarchar 50
Description nvarchar 50
Parameters nvarchar 200
rowguid uniqueidentifier 16

My app.exe.config file looks as follows:


<?xml version="1.0" encoding="utf-8" ?>

<!-- .NET application configuration file

The .NET Compact Framework does not support application configuration
files,
but log4net supports using configuration files with similar names and
structure,
to store the log4net configuration.
-->

<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>

<appender name="ADONetAppender_SqlServer"
type="log4net.Appender.ADONetAppender" >
<param name="ConnectionType"
value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<param name="ConnectionString" value="workstation
id=ACHATSCHITZ;packet size=4096;user id=sa;pwd=sa;data
source=achatschitz;persist security info=False;initial catalog=HelpDesk" />
<commandText value="INSERT INTO Instrumentation
([Date],[UserName],[ClassName],[Method],[Description],[Parameters]) VALUES
(@log_date, @thread, @log_level, @logger, @message, @exception)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%t" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%p" />
</layout>
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%c" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%m" />
</layout>
</parameter>
<parameter>
<parameterName value="@exception" />
<dbType value="String" />
<size value="200" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="ADONetAppender" />
</root>

</log4net>

</configuration>

And in my application I wrote the following code:

protected static readonly ILog log = LogManager.GetLogger(typeof(Login));
log4net.Config.DOMConfigurator.Configure();

and in the method where I want to log information I add the following:

log.Debug("The program got here!");
LogManager.Shutdown();

But when I execute my application and invoke this method, nothing happens.
Does anybody know what went wrong or what I have forgotten??:(

thx

robert



# re: Log4Net is Crap4Crap 12/15/2004 3:27 PM MrMad
It took me two days to get logging set up properly. What a pain. The documentaion is a complete joke as you say. I never did get the [assembly: log4net.Config.DOMConfigurator... stuff to work. Wish I had found the above examples before I started. Why is it that almost every .Net code sample is of the 'hello world' variety? Aaaargh!

# re: Log4Net is Crap4Crap 1/10/2005 2:51 PM Tom Gilkison
If you are having trouble using log4net in an ASP.NET application, I have posted a tutorial that may help...
<a href="http://tom.gilki.org/programming/net/120604/">log4net Tutorial: Using log4net in an ASP.NET Application</a>

For those who have the logging framework working, please post more tutorials!

Cheers!

# re: Log4Net is Crap4Crap 1/10/2005 2:53 PM Tom Gilkison
I wish there was a preview button! Click this link instead...
http://tom.gilki.org/programming/net/120604/

# re: Log4Net is Crap4Crap 1/25/2005 4:56 AM Günther Schabus
Can anyone please describe the configurationsetting when using log4net and ChainSaw V2?

I've no Problems configuring a file- or Consoleappender or even an UDPAppender.

But if i want to view the log with chainsaw i am not able to manage this. The only thing I did is installing chainsaw on my Machine (WebStart). And now what?

Thank you for your time.


# re: Log4Net is Crap4Crap 1/28/2005 11:56 AM Gerald
I am using log4net 1.1 and am having a really hard time getting it to work with a C# Windows service.

Here is the code I put in the Main:

StreamWriter writer = new StreamWriter("c:\\tmp\\log4net.log");

writer.AutoFlush = true;

Console.SetOut(writer);

log4net.helpers.LogLog.SetInternalDebugging(true);

log4net.Config.DOMConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log4net.config"));

_logger = LogManager.GetLogger(typeof(Service));

_logger.Debug("Running service.");

I don't get the log4net debug output or the logged message.

If I put the very same code into a console application I see both the log4net debug output and the logged message. Has anyone used log4net in a Windows service? Are there any special considerations.

Thanks for you time.

Gerald

# re: Log4Net is Crap4Crap 2/1/2005 8:10 AM Matias
Finally everything is working here too!
AssemblyInfo.cs has:

// Configure log4net using the .config file
[assembly: log4net.Config.DOMConfigurator(Watch=true)]

Be sure not only to have the latest log4net.dll as reference, but also the log4net.xml too! Worked for me.

My appender is similar to the above mentioned, but the instance I use is:

private static readonly log4net.ILog log = log4net.LogManager.GetLogger("Class Name");

So that the class name appears in the log file... Very useful.

Happy loggin'!


# re: Log4Net is Crap4Crap 2/18/2005 7:55 AM Reinout
I tried using it in a WebApp.
Works, but not fine...
When using FileAppender with: <param name="AppendToFile" value="false" /> it is working the first time only. After that no logging is done.
Secondly, I have to call: log4net.LogManager.Shutdown(); because I want to use the file as an attachment in an email. If you do not force shutdown, the file is locked and cannot be attached.
Maybe there is way to configure at runtime to use a text file log{date}{time}. So every time the application loads, it creates a new log file.
Any ideas, comments, suggestions?
Reinout


# re: Log4Net is Crap4Crap 2/20/2005 2:42 AM Dion

I've just written a weblog entry "4 Tips for using Log4NET's ADONetAppender in ASP.NET" that might help you implementing the ADONetAppender:

http://weblogs.asp.net/dr.netjes/archive/2005/02/16/374780.aspx

# S dot One heeft het over .NET &raquo; Log4Net is crap? 2/25/2005 9:17 AM
S dot One heeft het over .NET &raquo; Log4Net is crap?

# re: Log4Net is Crap4Crap 3/3/2005 11:00 AM Tomitza
Please help.

# re: Log4Net is Crap4Crap 3/3/2005 11:05 AM Tomitza
Please,please help!!!

I cannot use log4net from inside a dll. For everything i did, even the programatically loading of the configuration file, nothing worked.

If used in an Windows or Console application, where the main application makes a call to another application built as an dll that uses log4net, it works.
The main application has nothing to do with log4net, as the called one does all the logging.

But if my program (Office Shared Add-In) uses that dll (which uses log4net for logging ) , it doesn't log anything.

It took me a hole day to give it up....



# re: Log4Net is Crap4Crap 3/8/2005 4:13 PM Owen Corpening
I follow all the steps, but no log file. Perhaps I am looking in the wrong place?

# re: Log4Net is Crap4Crap 3/14/2005 2:32 PM wesley
Can someone send me a example to use log4net in Windows Service?

# Log4Net is not that bad. 3/23/2005 10:29 AM Marco
log4net is really not that bad. But I agree that quite some documentation is missing. What's stopping us.

Let's write it down. See on the conversion patern

http://bizknowledge.blogspot.com/2005/03/instrumentation-logging.html



# re: Log4Net is Crap4Crap 4/11/2005 7:40 AM Dima
People, People!!!!
It is free!!!! How can you compain on something you get for free???

Don't wanna use - dont use - but respect tons of work people gave for F#$^# free in order to help you a little bit with the logs.

Wanna get the super-druper documentation? Why not order it from one of the log4net developers for money...
Realy...



# re: Log4Net is Crap4Crap 4/21/2005 11:01 AM D Cameron
For a Windows Service and a FileAppender use the following...
public class MyService : System.ServiceProcess.ServiceBase
{
private static ILog logger;

public MyService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();

Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
logger = LogManager.GetLogger(typeof(MyService));
DOMConfigurator.Configure(new FileInfo(@"d:\MyService\log4net.config"));


# re: Log4Net is Crap4Crap 4/22/2005 11:46 AM Log4Net question
Hello,

If date is 10 days older i need to delete the old log files from bin directory. Could any one please help me how to do this. I am very new to this tool. Any help is really appreicated.

This is the following code. We are using.

<log4net>
<appender name="Console" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<!-- Pattern to output the caller's file name and line number -->
<conversionPattern value="%5level [%thread] - %message%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO" />
</filter>
</appender>

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="temp.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />

<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %level %thread %logger - %message%newline" />
</layout>
</appender>

<root>
<level value="DEBUG" />
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>
</log4net>




# re: Log4Net is Crap4Crap 4/26/2005 3:31 PM sKumar
Hi,

I am new to Log4Net. I configured my Web.config file to use the Logger, Appender, but I am having trouble change the level. Everytime I change the Logger level to INFO I am still getting Debug and other levels being logged.

Need some help here. I have attached the web.config file settings below.


<log4net>
<logger name="AppLogging.Main">
<level value="INFO" />
<appender-ref ref="LogFileAppender" />
</logger>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="C:\\Temp\\LogTest2.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>

<root>
<level value="INFO" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>

# re: Log4Net is Crap4Crap 4/27/2005 4:25 AM deepa
Is it possible to direct log output to different appenders by level?

# re: Log4Net is Crap4Crap 5/12/2005 2:17 PM Crap Reader
I get mine up and running in 10 minutes, if you read the documentation and look at the example config. You should be fine.

By the way, if you think log4net is Crap4Crap, you might want to change your blog to Michael Flanakin's Web Crap :(

# re: Log4Net is Crap4Crap 5/14/2005 10:47 AM Jordan
For those having trouble getting ADONetAppender in Log4Net working, check the following:

1) Make sure that the value of dbType is set to a valid dbType enumeration for the database provider (as opposed to the the native type insde the database). Many people set it to “VARCHAR” or “CHAR”, when in actually it should be “String”.

2) Also, be sure that your conversionPattern values are valid. You can test them in one of the other Trace appenders prior to dropping them into the ADONetAppender

3) ADONetAppender will crash out silently if not configured correctly, so don’t be afraid to lift up the hood. You can enable internal debugging by following the instructions in the Log4Net docs at /doc/manual/faq.html#internalDebug . If you are using Log4Net in an ASP.NET application, you can also set up Trace commands to write out to your browser. To do so, add the Log4Net project to your solution, then open up the

log4net.Repository.Hierarchy.DOMHierarchyConfigurator.cs

Add “using System.Web;” to the top of the file, and then drop in trace calls at appropriate steps like this:

“HttpContext.Current.Trace.Warn("[Step Name]", “meaning full trace note");”

The primary functions of interest are:
protected IAppender FindAppenderByReference
protected IAppender ParseAppender
protected void ParseChildrenOfLoggerElement
protected void ParseChildrenOfLoggerElement
protected void SetParamete

When you are done, you should be able to see where Log4Net is dropping out. Don’t forget to remove the reference and trace events after you are done.

I hope this helps. As I am sure you know, Log4Net is a port of a very successful and mature Java framework that has successfully endured, and benefited as a direct result of, critical assessment by the development community. Open source software is usually thin on documentation and rarely has a step-by-step or one button click installer. Being forced to develop an understanding of a tool prior to using it can be frustrating for those who are used to Microsoft’s auto-installers and snap-in administration panels. I’m not knocking MS, they have hands down the best tool interfaces, installer’s, and documentation that money can motivate people to produce (perhaps even too much documentation). My point is that if Log4Net was a commercial piece of software, you would be justified in complaining about the lack of documentation or how difficult it is to configure it. However, Log4Net is Open Source, so your words of frustration could/should potentially be the seed of motivation to contribute to the community effort. You take the time to share your frustration with the audience of your blog, which is certainly your prerogative. However I propose that your readers would benefit more from the knowledge you gained during your experience. If you were inclined, you could even join the community effort and spend some time writing better or just reorganizing the Log4Net docs.


# re: Log4Net is Crap4Crap 5/26/2005 7:09 AM intenter
Log4Net is a very good thing, but i have unexpected problem with my own Appender.

I tried to configure it in runtime, because my Appender is a subclass of ADONetAppender, and I have got ConnectionString only in runtime.

MyDbAppender app = new MyDbAppender(connectonString);
log4net.Config.BasicConfigurator.Configure(app);

log = LogManager.GetLogger(this.GetType());
log.Info("Ok");

But this code has no effect! My Appender didn't "registered" in log4net Repository, and there was no log ounput in application at all. There where no exception during configuration.

I cannot find solution of this problem!

# re: Log4Net is Crap4Crap 5/26/2005 7:47 AM intenter
I found solution: I had to call ActivateOptions method directly.

# re: Log4Net is Crap4Crap 8/18/2005 7:09 AM Brennan Stehling
It has been a while since you posted this. Have things improved? I also had problems configuring log4net, but I was placing the configuration into web.config for ASP.NET 2.0 Beta 1. It was not working and it was not telling me why. So finally I created a separate log4net.xml file and referenced it as a regular value in web.config. When I loaded that independently it was much easier to troubleshoot. And it does seem now the documentation is much more complete.

# re: Log4Net is Crap4Crap 8/18/2005 9:44 AM Michael Flanakin
I actually haven't used it since my first problems. I do have plans on using it again, tho. I am hoping documentation is more complete. I think most of the problems were around that area.

Thanks for the tip!

# re: Log4Net is Crap4Crap 12/12/2005 10:16 PM Prashant
I have used this Attribute and it works fine for APP.COnfig file [assembly: log4net.Config.XmlConfigurator(Watch=true)]
Suppose i change config file as MYApp.Log4net this attribute does nt work.
[assembly: log4net.Config.DOMConfigurator(ConfigFileExtension="log4net",Watch=true)]

# re: Log4Net is Crap4Crap 12/12/2005 10:19 PM Prashant
How do i Trace Level for only two verbose
ex: DEBUG,TRACE in this tag.
<level value="DEBUG,TRACE" />
i need to log only two levels here.

# re: Log4Net is Crap4Crap 12/12/2005 10:21 PM Prashant
How to log using programitically log4net.
actually i dont need Config file itself as some one can meddle with this settings.


# re: Log4Net is Crap4Crap 12/12/2005 10:23 PM Prashant
log4net talks about herichachay logging .
i want to log all class /module wise in separate log files. can i do this , how?

# re: Log4Net is Crap4Crap 12/27/2005 2:59 AM Sukhendu Chakraborty
how can i use log4Net inside an assembly
from an asp.net application

# re: Log4Net is Crap4Crap 1/6/2006 6:10 AM Vjain
trying to use log4net for windows forms, but unable to configure...
my config file name: "log.exe.log4net"
app is: log.exe
and using:[assembly: log4net.Config.DOMConfigurator(ConfigFileExtension="log4net", Watch=true)]
in assemblyinfo.cs
----------------------------------
in my form1 class: private static readonly ILog logger = LogManager.GetLogger(typeof(Form1));


config file is: "log.exe.log4net" having
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="true">
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="log-file.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>

now please tell me what i'm missing....
Thanks for ur reply..


# re: Log4Net is Crap4Crap 1/19/2006 10:03 PM Maria
Can anyone tell how to log to a new file for each day using log4net??

# re: Log4Net is Crap4Crap 1/31/2006 7:56 PM Rogelio
Hi, I have 2 questions:

1. The same question that Maria posted: How can I make a new file for each day? I am actually using this configuration:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\\TEMP_log\\test.log" />
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="10" />
<maximumFileSize value="1000KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%d] %-5p : %m%n" />
</layout>
</appender>

2. Where do you recommend me to put this code:
log4net.Config.DOMConfigurator.Configure();
I actually put this code in the global.asax.cs:
protected void Application_Start(Object sender, EventArgs e)
{
log4net.Config.DOMConfigurator.Configure();
}

Is this correct? Any sugestions?

Thanks for your time.


# re: Log4Net is Crap4Crap 1/31/2006 8:15 PM Maria
Rogelio -
Yes,You have to put the code in Application_start.
Any reply for ur first question.I'm looking for its solution for the past one week.But what i need is i need separate log file for each day,irrespective of the size of the file.You have written like write to a new code when the file exceeds a particular limit isnt?
Correct me if i am wrong...


# re: Log4Net is Crap4Crap 2/14/2006 1:46 PM lo4netuserven
How to solve RollingFileAppender issues? In my web server, log4net stops creating new files after it reaches its rolling file size limit. Please help/advise.

# re: Log4Net stops logging 2/22/2006 6:03 AM JB
Has anyone had any issues where Log4Net just stops logging out of the blue? When this happens, I have to perform a server reboot. I've tried recycling IIS5, but that doesn't start up the logging again.

# re: Log4Net is Crap4Crap 3/8/2006 6:04 AM Wentu
Hi all

My problem is i can't debug log4net. I am using an AdoNETAppender on two servers. On the first it works, on the second, it doesn't. So I am trying to debug log4net to understand where's my problem. I went on the working server and modified the INSERT query so that it fails (I wrote "FOOINSERT" instead of INSERT). Then I specified debug="true" in the log4net configuration. The logging fails but on the console i have no note about this. Just a lot of lines like this one:
log4net: DOMConfigurator: Setting Property [Layout] to object [log4net.Layout.PatternLayout]

and ending with

log4net: DOMConfigurator: Hierarchy Threshold []

Why can't i see any error log ?

Could You please send any answer also to il_wentu@excite.com ?

Thanks for Your help.

# re: Log4Net is Crap4Crap 3/24/2006 2:31 AM vb
for me logging is working but getting error message as:
"System.Configuration.ConfigurationException: Could not create log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=null"

can anyone help me on this

# re: Log4Net is Crap4Crap 4/3/2006 5:39 PM Scott
For those of your working on ASP.net applications and struggling to get anything to show you must put the
log4net.Config.DOMConfigurator.Configure();
line in the application_start method of global.asax

This is because due to limitations of .net framework the application start event is not obtainable from anywhere other than this location (HttpModules can't react to it).

This is also why if you create a dll with logging and use it in another application you cannot get logging to work, there is no configuration called from the application importing the DLL. You would need to reference log4net in the calling application for the DLL you're using to activate logging.

I hope this helps someone.

# re: Log4Net is Crap4Crap 6/27/2006 12:47 PM lorena
Does anybody know how to log to different files??. I am using RollingFileAppender, but I would like to log to log1.txt all Info and log2.txt all Error, but what I get is that all log info is written to both files.
Thanks


# re: Log4Net is Crap4Crap 12/5/2006 2:27 PM DotNetSpace

There is a very good example in
http://www.dotnetspace.com/articles/general-articles/using-log4net---very-quick-start.html

I hope it can help you all.

# re: Log4Net is Crap4Crap 3/3/2007 8:20 AM David
Hi Dion,

thanks a lot for the hint regarding buffersize set to 1. That's exactly what i was looking for!

# Sharon Roberts 4/18/2007 8:40 AM Susan Lewis
The 5840 Dorothy Baker blog

# re: Log4Net is Crap4Crap 5/30/2008 10:11 PM Tom
I was going nuts on trying to figure out how to get the rollingfileappender working in a c# windows service. Added the entry to the assembly was just the trick!

Thanks for the info

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 4 and 5 and type the answer here: