【问题标题】:Using ServiceStack Mini Profiler in self-hosted console application在自托管控制台应用程序中使用 ServiceStack Mini Profiler
【发布时间】:2013-05-06 21:19:32
【问题描述】:

是否可以在自托管控制台应用程序中使用 ServiceStack Mini Profiler?如果是,我应该在哪里放置探查器启用/禁用代码?在 ASP.NET 托管的 ServiceStack 中,它通常位于 Application_BeginRequestApplication_EndRequest 方法中。

【问题讨论】:

  • 在自托管模式下运行 ServiceStack 时,HttpContext.Current 始终为空。看来 MiniProfiler 依赖它。

标签: c# console-application servicestack profiler self-hosting


【解决方案1】:

你可以这样做:

namespace ConsoleApplication1 {
  class Program {
    static void Main(string[] args) {
      // enable here

      // your code

      // disable here
    }
  }
}

或者在构造函数和析构函数中是这样的:

namespace ConsoleApplication1 {
  class Program {
    Program() {
      // enable here
    }

    ~Program(){
      // disable here
    }

    static void Main(string[] args) {
      // your code
    }
  }
}

【讨论】:

  • 你能说一下,更详细的实现,尝试在 ctor 上使用 profiler.start 和在 dispose 上使用 profiler.stop 但没有结果(js 对话框与 web 一样)
【解决方案2】:
public abstract class MyHostBase : AppSelfHostBase
{
    this.GlobalRequestFilters.Add(OnBeginOfRequest);
    this.GlobalResponseFilters.Add(OnEnfOfRequest);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-12
    • 2014-11-19
    • 2017-07-03
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 2013-05-07
    • 2012-10-21
    相关资源
    最近更新 更多