ServiceStack - 自动查询请求日志问题

时间:2017-06-26 12:40:11

标签: servicestack autoquery-servicestack

我很难获得在servicestack服务中工作的请求日志的示例自定义自动查询。

我正在使用VS2017并使用ServiceStack ASP.NET空模板来创建新的解决方案。然后我在http://docs.servicestack.net/autoquery-service#view-request-logs-in-autoquery-viewerhttpsgithubcomservicestackadmin中添加了示例中的一些代码,即以下类QueryRequestLogs,CustomAutoQueryDataServices和TodayLogs。我的apphost是 -

//VS.NET Template Info: https://servicestack.net/vs-templates/EmptyAspNet
public class AppHost : AppHostBase
{
    /// <summary>
    /// Base constructor requires a Name and Assembly where web service implementation is located
    /// </summary>
    public AppHost()
        : base("Autoquery", typeof(MyServices).Assembly) { }

    /// <summary>
    /// Application specific configuration
    /// This method should initialize any IoC resources utilized by your web service classes.
    /// </summary>
    public override void Configure(Container container)
    {

        Plugins.Add(new RequestLogsFeature
        {
            RequestLogger = new CsvRequestLogger(
    files: new FileSystemVirtualPathProvider(this, Config.WebHostPhysicalPath),
    requestLogsPattern: "requestlogs/{year}-{month}/{year}-{month}-{day}.csv",
    errorLogsPattern: "requestlogs/{year}-{month}/{year}-{month}-{day}-errors.csv",
    appendEvery: TimeSpan.FromSeconds(1)
),
            EnableResponseTracking = true
        });

        Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });
        Plugins.Add(new AdminFeature());
    }
}

我做了几个电话,以确保请求日志中有一些内容。然后我使用元数据页面中的链接转到自动查询查看器。无论我从左侧尝试哪种搜索选项,我都会得到一个“对象引用未设置为对象的实例”。 System.NullReferenceException来自行

var q = AutoQuery.CreateQuery(query, Request,
    db: new MemoryDataSource<RequestLogEntry>(logs, query, Request));

in

public class CustomAutoQueryDataServices : Service
{
    public IAutoQueryData AutoQuery { get; set; }

    public object Any(QueryRequestLogs query)
    {
        var date = query.Date.GetValueOrDefault(DateTime.UtcNow);
        var logSuffix = query.ViewErrors ? "-errors" : "";
        var csvLogsFile = VirtualFileSources.GetFile(
            "requestlogs/{0}-{1}/{0}-{1}-{2}{3}.csv".Fmt(
                date.Year.ToString("0000"),
                date.Month.ToString("00"),
                date.Day.ToString("00"),
                logSuffix));

        if (csvLogsFile == null)
            throw HttpError.NotFound("No logs found on " + date.ToShortDateString());

        var logs = csvLogsFile.ReadAllText().FromCsv<List<RequestLogEntry>>();
        try
        {
            var q = AutoQuery.CreateQuery(query, Request,
                db: new MemoryDataSource<RequestLogEntry>(logs, query, Request));
            return AutoQuery.Execute(query, q);
        }
        catch (Exception ex)
        {
            return ex;
        }

    }

完整堆栈跟踪是:

at Autoquery.ServiceInterface.CustomAutoQueryDataServices.Any(QueryRequestLogs query) in C:\Repos\test\Autoquery\Autoquery\Autoquery.ServiceInterface\CustomAutoQueryDataServices.cs:line 32
at ServiceStack.Host.ServiceRunner`1.Execute(IRequest request, Object instance, TRequest requestDto)
at ServiceStack.Host.ServiceExec`1.Execute(IRequest request, Object instance, Object requestDto, String requestName)
at ServiceStack.Host.ServiceRequestExec`2.Execute(IRequest requestContext, Object instance, Object request)
at ServiceStack.Host.ServiceController.ManagedServiceExec(ServiceExecFn serviceExec, IService service, IRequest request, Object requestDto)
at ServiceStack.Host.ServiceController.<>c__DisplayClass36_0.<RegisterServiceExecutor>b__0(IRequest req, Object dto)
at ServiceStack.Host.ServiceController.Execute(Object requestDto, IRequest req)
at ServiceStack.HostContext.ExecuteService(Object request, IRequest httpReq)
at ServiceStack.Host.RestHandler.GetResponse(IRequest request, Object requestDto)
at ServiceStack.Host.RestHandler.<>c__DisplayClass13_1.<ProcessRequestAsync>b__0(Task t)
at ServiceStack.AsyncExtensions.Continue[TOut](Task task, Func`2 next)
at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)
at ServiceStack.Host.Handlers.HttpAsyncTaskHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

当我调试时,每个日志,查询和请求参数都不为空。

我假设我错过了一些简单的东西,但我不知道是什么,也不知道如何进一步调试。

1 个答案:

答案 0 :(得分:2)

NullReferenceException是因为AutoQuery依赖项为null:

public IAutoQueryData AutoQuery { get; set; }

这是null,因为您只导入了AutoQuery RDBMS功能:

Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });

而不是AutoQuery数据功能:

Plugins.Add(new AutoQueryDataFeature { MaxLimit = 100 });

使用任何(非RDBMS)AutoQuery Data Sources时都需要。