|
Hi,
I am new to the OOP in asp.net.
I have created a console application, within which I call another class, let us call it class A.
I want to logging of events going on in the application.
I am using the app.config, the define the log file path. and using simple System.IO.File.WriteAll to write to this file.
But for some reason, the log captures only the statements written in the main part of the app and not what was logged in class A. I am writing to the same log file.
How can I make it so the log file keeps appending??
Much appreciated!!
|
|
|
|
|
Try using something like log4net or NLog both of which are free and easy to use, rather than rolling your own. I use log4net in a console application and it writes clear and concise log files with pipe-delimited fields; so easy to parse and view, if required. Very quikc and easy to set up and integrate into your code.
No real way to know what is wrong with your code if you don't provide samples/exceptions.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
yup - while I have some issues with log4net (I use a custom startup so I can dynamically define where the log file goes based on where the app exe is located, rather than a fixed path/location for log files), I'd recommend it to anyone starting out using/needing logging
|
|
|
|
|
I have tried the Nlog tool. It worked well with one project, and when I tried to add it to another project, it was a complete mess. I was not able to add the config file specific to this second project.
I read that you need to install the tool, not having any pojects opened, just only the VS opened. I did that as well, but it was not straight forward.
|
|
|
|
|
Can you have the class A raise an event and have the parent class attach a handler to write the log? I've done that in the past for similar situations.
|
|
|
|
|
I used Nlog for logging.
It has a separate config file, and specifies the path to log all the application events.
I want to send this log file in an email. How would I get the path to this location in my program?
|
|
|
|
|
Dunno. Never used it. Can't you read the config file?
|
|
|
|