I wanted to ask for some logging mechanism or framework with specific function. I am already loggin in my app (dll library) with
Log.WriteLine("{0}.{1}()", System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType, System.Reflection.MethodInfo.GetCurrentMethod().Name);
where the Log is static class with capability to write to file using Streamwriter
public void LogWriteLine(string text, params object[] args) {
lock (this) {
StreamWriter log = new StreamWriter(logFile, true);
if (log != null) {
log.WriteLine("{0:yyyy-MM-dd HH:mm:ss} {1}", DateTime.Now, String.Format(text, args));
log.Flush();
log.Close();
}
}
}
My problem is, I don’t have the Log.WriteLine call all over my app, just in specific parts of apps, because it would create really big file. But now, I build my app, and posted it to the developers, they worked on it for some days. After that they send me bugs, but in my version the bugs are not anymore (the development continues on the app, so they could be fixed).
So I wanted to have in the app some setting file, to tell the app that I need more logs and be able to run the testers version of app without to rebuild it just with different settings for logger.
In short: how can I tell the app form some settings file, to log something specific only, for example just one class, or one method?
I have needed to do a similar sort of thing. This is how I did it.
I created a category class and use that as a parameter when the logging object is initialised.
As you can see by the line “Log.GetInstance().AddCategory(this);”, my logging object is a singleton.
The singleton, has some methods to add and remove categories
When processing the log event it is now just a case of checking the active state of the category to see if that message is required.
Finally, if you want the message to be displayed on a screen, you’ll need to handle the message event in the UI thread. Here is a sample from one of my list view components…