You should be using Common.Logging to share your logger between projects.
Common.Logging is a great and lightweight way to share dependencies without requiring that you also share implementation. It is how several of my projects that use Log4Net are able to shares resources with another team that uses NLog. But that is not what I am here to talk about!
How do you log performance quickly and easily?
No, I do not mean performance counters. No, I do not mean interceptors for dependency injection. I want something far more lightweight and simplistic! What I want is the ability to simply log if too much time is spent in a specific block of code. For example...
public void MyMethod1(ILog log)
{
// If this using block takes more than 100 milliseconds,
// then I want it to write to my Info log. However
// if this using block takes more than 1 second,
// then I want it to write to my Warn log instead.
using (log.PerfElapsedTimer("MyMethod took too long!"))
{
var obj = GetFromApi();
SaveToDatabase(obj);
}
}
The PerfElapsedTimer is just a simple little extension method that I wrote, under the hood it just wraps a Stopwatch in an IDisposable. Feel free to grab the code from below and start using it yourself.