Tuesday, 20 August 2013

Accessing logging functionality from a class library

Accessing logging functionality from a class library

I have a solution with two projects, my WPF application project which
references the second project, a class library. The WPF application uses
Caliburn.Micro. I would like some classes in the library to log messages
through Caliburn.Micro's logging facility (which I've set up with log4net,
but that should be irrelevant).
To see if this would work, I put the following class into my library to
see if anything would show up in my log, and called it from one of my
viewmodels:
public class TempClass {
private static ILog Log = LogManager.GetLog(typeof(TempClass));
public static void LogSomething(string something) {
Log.Info(something);
}
}
It didn't work.
The class library can't reference my WPF application's project because
that would cause a circular reference. I figure I could have a static
object in the library that holds a reference to the WPF app's LogManager,
and I could set that up in my bootstrapper, but that doesn't feel like the
right solution.
What is a good solution to this problem?

No comments:

Post a Comment