Getting log4net to work *just* the way I want it to!

M

Marc Scheuner

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.

What I'd like to achieve is logging into a file that I can specify the
file name format of: something like <prefix>-<date in my own custom
format>.log.

With the rolling file appender, I *almost* get it, but when I specify
"DateFormat=YYYYMMDD", then what I end up with are files such as
mylog_2006-09-01.log
mylog_2006-09-01.log2006-09-02
mylog_2006-09-01.log2006-09-03
and so on. *NOT* what I wanted, really ! I want the date string to be
in the NAME of the file, and *NOT* just appended to the extension of
the file. Because this way, I can't get all the files by specifying a
"*.log" dir mask......

Also, another trouble is that Windows services seem to "hold on" to
their log file, and when I start a Windows service on Sept 1th, 2006,
it will log into Service_2006-09-01.log and then lock that, and even
if more messages come in on the 2nd and 3rd of September, those will
still be written into the 2006-09-01.log file.

So my two main complaints / questions are:

* How do I tell log4net to format the file name according to
*MY* choice?
mylog_YYYY-MM-DD.log and nothing else

* How do I get Windows Services to "switch" to a new log file,
if a message appears
on Sept 2nd and use service_2006-09-02.log instead of
writing all into the file for Sept 1st?

2) The AdoNetAppender doesn't seem to work - period. What the hell is
up with that??

* I have a suitable table (I think) for the messages
* I configured the AdoNetAppender for *ALL* messages from the
root level down
* I specified the insert statement and the fields collection
in the log4net.config

Still, it just doesn't seem to log ANYTHING at all..... the
RollingFileAppender works just fine......

Any ideas??

Thanks!
Marc
 
O

Otis Mukinfus

1. log4net is not a Microsoft product. Try: http://logging.apache.org/log4net/

2. AdoNetAppender is not a Microsoft product. Try:
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppender.html

3. You can read up on how Microsoft services work at
http://www.msdn.microsoft.com

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.

What I'd like to achieve is logging into a file that I can specify the
file name format of: something like <prefix>-<date in my own custom
format>.log.

With the rolling file appender, I *almost* get it, but when I specify
"DateFormat=YYYYMMDD", then what I end up with are files such as
mylog_2006-09-01.log
mylog_2006-09-01.log2006-09-02
mylog_2006-09-01.log2006-09-03
and so on. *NOT* what I wanted, really ! I want the date string to be
in the NAME of the file, and *NOT* just appended to the extension of
the file. Because this way, I can't get all the files by specifying a
"*.log" dir mask......

Also, another trouble is that Windows services seem to "hold on" to
their log file, and when I start a Windows service on Sept 1th, 2006,
it will log into Service_2006-09-01.log and then lock that, and even
if more messages come in on the 2nd and 3rd of September, those will
still be written into the 2006-09-01.log file.

So my two main complaints / questions are:

* How do I tell log4net to format the file name according to
*MY* choice?
mylog_YYYY-MM-DD.log and nothing else

* How do I get Windows Services to "switch" to a new log file,
if a message appears
on Sept 2nd and use service_2006-09-02.log instead of
writing all into the file for Sept 1st?

2) The AdoNetAppender doesn't seem to work - period. What the hell is
up with that??

* I have a suitable table (I think) for the messages
* I configured the AdoNetAppender for *ALL* messages from the
root level down
* I specified the insert statement and the fields collection
in the log4net.config

Still, it just doesn't seem to log ANYTHING at all..... the
RollingFileAppender works just fine......

Any ideas??

Thanks!
Marc
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top