Added some logging at last!

This commit is contained in:
TomPallister
2016-11-04 20:17:15 +00:00
parent 47afc850ff
commit 8582ba45a9
19 changed files with 352 additions and 73 deletions

View File

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Ocelot.Infrastructure.RequestData;
using Ocelot.Logging;
using Ocelot.Middleware;
namespace Ocelot.Cache.Middleware
@ -11,11 +12,11 @@ namespace Ocelot.Cache.Middleware
public class OutputCacheMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger _logger;
private readonly IOcelotLogger _logger;
private readonly IOcelotCache<HttpResponseMessage> _outputCache;
public OutputCacheMiddleware(RequestDelegate next,
ILoggerFactory loggerFactory,
public OutputCacheMiddleware(RequestDelegate next,
IOcelotLoggerFactory loggerFactory,
IRequestScopedDataRepository scopedDataRepository,
IOcelotCache<HttpResponseMessage> outputCache)
:base(scopedDataRepository)
@ -35,26 +36,30 @@ namespace Ocelot.Cache.Middleware
return;
}
_logger.LogDebug("OutputCacheMiddleware.Invoke stared checking cache for downstreamUrlKey", downstreamUrlKey);
_logger.LogDebug("started checking cache for {downstreamUrlKey}", downstreamUrlKey);
var cached = _outputCache.Get(downstreamUrlKey);
if (cached != null)
{
_logger.LogDebug("cache entry exists for {downstreamUrlKey}", downstreamUrlKey);
SetHttpResponseMessageThisRequest(cached);
_logger.LogDebug("OutputCacheMiddleware.Invoke finished returned cached response for downstreamUrlKey", downstreamUrlKey);
_logger.LogDebug("finished returned cached response for {downstreamUrlKey}", downstreamUrlKey);
return;
}
_logger.LogDebug("OutputCacheMiddleware.Invoke no resonse cached for downstreamUrlKey", downstreamUrlKey);
_logger.LogDebug("no resonse cached for {downstreamUrlKey}", downstreamUrlKey);
await _next.Invoke(context);
_logger.LogDebug("succesfully called next middleware");
if (PipelineError())
{
_logger.LogDebug("OutputCacheMiddleware.Invoke there was a pipeline error for downstreamUrlKey", downstreamUrlKey);
_logger.LogDebug("there was a pipeline error for {downstreamUrlKey}", downstreamUrlKey);
return;
}
@ -63,7 +68,7 @@ namespace Ocelot.Cache.Middleware
_outputCache.Add(downstreamUrlKey, response, TimeSpan.FromSeconds(DownstreamRoute.ReRoute.FileCacheOptions.TtlSeconds));
_logger.LogDebug("OutputCacheMiddleware.Invoke finished response added to cache for downstreamUrlKey", downstreamUrlKey);
_logger.LogDebug("finished response added to cache for {downstreamUrlKey}", downstreamUrlKey);
}
}
}