Search code examples
c#mvc-mini-profilerminiprofiler

How can I have Miniprofiler just call may log method for the profile messages


I am building a windows service.

I am trying to have miniprofiler, intercept ado.net calls and hand the messages to my application's logging system.

All miniprofiler needs to do is to call a static method Log(string text).

I went through the following post and learned how to intercept ado.net calls:

Using MiniProfiler for direct ADO.net calls

It seems that the only unsolved puzzle is to have miniprofile call my log method. How can I do that?

I went through the site http://miniprofiler.com/, but the documentation is minimal.


Solution

  • In short: this isn't something MiniProfiler is designed to do, because that's not profiling.

    However, you lucked out in how MiniProfiler is implemented here. You can implement IDbProfiler yourself that just calls the logger. There are only a handful of methods. Here's MiniProfiler's implementation.

    If your implementation just calls your logging method(s), you can re-use all of the ADO.NET bits built for MiniProfiler like this:

    IDbProfiler logger = new YourLogger();
    var conn = new SqlServerConnection(myConnectionString);
    var profiledConn = new ProfiledDbConnection(cnn, logger);
    // ...do stuff with profiledConn