【问题标题】:Ormlite not profiled with ServiceStack MVC profilerOrmlite 未使用 ServiceStack MVC 分析器进行分析
【发布时间】:2013-02-03 08:05:25
【问题描述】:

我的服务堆栈 Web 服务中有 MVC 分析器,我看到请求被记录到 Nlog。

但是,当我尝试分析我的 PostgreSQL 数据库时,没有生成任何日志。

我的 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));

    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();
    }

【问题讨论】:

标签: c# servicestack ormlite-servicestack


【解决方案1】:

MiniProfiler 与日志记录无关,它控制分析结果是否在 MiniProfiler 查看器(位于 ServiceStack's auto-generated HTML5 Report pages)上可见。

您没有在此处显示任何日志记录代码,(我假设您将 ServiceStack.Logging 与 NLog 适配器一起使用)。配置它的最佳位置是在初始化 AppHost 之前,因此所有静态构造函数都使用配置的 Logging 提供程序,即:

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

【讨论】:

  • 谢谢。我以为我正在使用 ILog 接口,但发现它是在另一个程序集中定义的,因此没有使用 ServiceStack.Logging。我现在将切换到 ServiceStack.Logging.NLog。从您的回答中,我认为 sql 分析将被写入 Nlog 文件是错误的吗?我目前正在运行一个 Flex 客户端,需要分析 postgres。
  • 日志记录没有在 Profiler 中完成(与它无关),您所指的 OrmLite 中可能的日志记录 is here 并且它发生在 Debug 构建 OrmLite。
  • 要获得调试版本,我是否必须将源代码拉到并在调试中构建,还是可以获得调试版本二进制文件?
  • 是的,你必须从 src 编译,另一种方法是提供你自己的 ProfiledDbConnectionProfiledDbCommand 来拦截所有查询并记录它们。
  • 如果它确实符合您的要求。另一种选择是在 MiniProfiler 中提交带有选择加入标志的拉取请求,该标志仅启用日志记录:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-20
  • 2016-03-26
  • 2017-07-02
  • 1970-01-01
  • 2011-09-02
  • 1970-01-01
相关资源
最近更新 更多