Click here to Skip to main content
15,749,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having a smaller problem...
The folder structure of my web app looks like this:
/ (contains main web app files)
/logs (contains logfiles)
/services (contains web services)

All parts of the app are using a common error log function. The error logger writes to files in the /logs directory. To get a hold of the log directory the log function uses logDir = HttpContext.Current.Server.MapPath(logDir); to get hold of the log direcory which is stored in the web.config under AppSettings. Nothing strange. This works fine as long as error logging is done from pages in the root folder. However, when an .asmx page logs the log function tries to log in /services/logs. I've been trying to put "logs", "~logs" and other stuff in the setting in AppSettings. How do I solve this?


1 solution

It sounds like the ASMX service has a different root /sevices , and probably desirable.
You could parse the mappath to give the /logs directoy but, unless there is a specific requirement to log to there, IMO it is better to keep the logs seperate.

One further suggestion, you could look at Log4Net[^] it's free, open source and pretty robust to failure (the last point is difficult to achieve in a logger!). The one draw-back is that it isn't guarenteed that the log will be written to (i.e. if an exception is thrown while logging, the log entry might not be written - part of its fail-over nature). That said, I've used it lots and had very few problems. One further thing is that it allows you to log to different stores, such as SQL or Text ( or a combination, or a custom store!) it also auto-rolls up logs if you want, and you can define a retention policy. It can be a little difficult to configure, but there are lots of resources out there. I'm not connected to the log4net project BTW, I just think it is fantastic :-).
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900