|
-
Jan 20th, 2011, 02:23 PM
#1
Automating error logging
Hi,
I am trying to create a class library that I can re-use in various projects. The library should handle error logging. It's nothing too special, I just want to log various things such as the exception/message, time of occurrence, some system information such as computer name, username, OS version, etc, and finally the application that the error occured in. I'd then write each entry to an XML file, and later I can create a 'logfile viewer' that reads the xml file and displays the errors in an easy to read fashion.
Anyway, the goal here is that I just have a class LogManager that I have to 'configure' before use in every application I want to use it in. After that I just call some shared methods (WriteError, WriteMessage, etc) and they would be written to the XML file, along with the application / system information.
This configuring should handle various things such as:
- Look up system information (OS, 64-bit or not, username, computername, etc)
- Look up application information (app name, version, etc)
- Look up the 'common app data' folder for that app and create the XML file there if it does not exist yet
All these things should happen automatically. I should not have to pass all the information to the LogManager class, as that would defeat the purpose of having a shared library (it would be less work to just do it separately for every project).
My problem now is as follows... The things I need to look up are pretty easy to find:
- Computername: My.Computer.Name
- Username: My.User.Name
- OS: Environment.OSVersion
- App name: My.Application.ProductName (I think)
- App version: My.Application.Version
- Common app data path: System.Windows.Forms.Application.CommonAppDataPath
However, I cannot use all of these in my separate class library, because they would return information about the class library, and not the project I am trying to log errors for... For example I guess the app name and version would return the name and version of the logging library, and the common app data path would be the folder for the logging library, not the folder for the project I'm logging for.
So, short of supplying these details manually in each separate project (which would defeat the purpose), what are my options here? Can my logging library somehow figure out which application is using it..? I guess not as that would be a circular reference...
So how can I solve this problem?
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|