JD.
JD.

Reputation: 15551

Ormlite not profiled with ServiceStack MVC profiler

I have the MVC profiler in my service stack web services and I see requests being logged to Nlog.

However, when I try to profile my PostgreSQL database, no logs are generated.

I have in my global.asax.cs:

        var dbConnectionFactory = new OrmLiteConnectionFactory(
            "Server=127.0.0.1;Port=5432;Database=mydatabase;User 
                                          Id=id;Password=password;")

                                      {
                                          ConnectionFilter = x => new 
                                      ProfiledDbConnection(x, Profiler.Current)
                                      };

        builder.RegisterInstance(dbConnectionFactory).
                         ExternallyOwned().As<IDbConnectionFactory>();

         var autofacContainer = builder.Build();
        //set Autofac as default Dependency Resolver for application
        DependencyResolver.SetResolver(new 
                                  AutofacDependencyResolver(autofacContainer));

and

    protected void Application_BeginRequest()
    {
        if (Request.IsLocal)
        {
            Profiler.Start();
        } 
    }

    protected void Application_EndRequest(object src, EventArgs e)
    {
        if (Profiler.Current != null)
        {
            Logger.Debug("profiling result id:{0}\nresult:{1}", Profiler.Current.Id,Profiler.Current.Render());
        }
        Profiler.Stop();
    }

Upvotes: 1

Views: 300

Answers (1)

mythz
mythz

Reputation: 143359

The MiniProfiler isn't related to logging, it's controls whether or not the profiled results are visible on the MiniProfiler viewer (that's on ServiceStack's auto-generated HTML5 Report pages).

You haven't shown any logging code here, (I'm assuming you're using ServiceStack.Logging with the NLog adapter). The best place to configure it is before you initialize the AppHost so all the static constructors use the configured Logging providers, i.e:

LogManager.LogFactory = new NLogFactory();
(new AppHost()).Init();

Upvotes: 1

Related Questions