Improving logging and request id (#189)

* hacking around to work out why logging and request id isnt working

* pass request id into logger so it can be structured, removed a bunch of debug logging we dont need because diagnostic trace gets it

* changed config dependency

* always have tracing available

* made it so we dont need to pass config into services.AddOcelot anymore with .net core 2.0

* add test

* lots of changes relating to logging and request ids, also updated documentation

* fixed failing test i missed
This commit is contained in:
Tom Pallister
2018-01-06 16:39:05 +00:00
committed by GitHub
parent 464f266148
commit 6a20baeb97
43 changed files with 562 additions and 197 deletions

View File

@ -1,5 +1,4 @@
using System;
using CacheManager.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
@ -8,7 +7,6 @@ using Microsoft.Extensions.Logging;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
using Ocelot.AcceptanceTests.Caching;
namespace Ocelot.AcceptanceTests
{
@ -26,7 +24,7 @@ namespace Ocelot.AcceptanceTests
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
public IConfiguration Configuration { get; }
public virtual void ConfigureServices(IServiceCollection services)
{
@ -35,48 +33,7 @@ namespace Ocelot.AcceptanceTests
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
app.UseOcelot().Wait();
}
}
public class Startup_WithCustomCacheHandle : AcceptanceTestsStartup
{
public Startup_WithCustomCacheHandle(IHostingEnvironment env) : base(env) { }
public override void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(Configuration)
.AddCacheManager((x) =>
{
x.WithMicrosoftLogging(log =>
{
log.AddConsole(LogLevel.Debug);
})
.WithJsonSerializer()
.WithHandle(typeof(InMemoryJsonHandle<>));
});
}
}
public class Startup_WithConsul_And_CustomCacheHandle : AcceptanceTestsStartup
{
public Startup_WithConsul_And_CustomCacheHandle(IHostingEnvironment env) : base(env) { }
public override void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(Configuration)
.AddCacheManager((x) =>
{
x.WithMicrosoftLogging(log =>
{
log.AddConsole(LogLevel.Debug);
})
.WithJsonSerializer()
.WithHandle(typeof(InMemoryJsonHandle<>));
})
.AddStoreOcelotConfigurationInConsul();
}
}
}

View File

@ -22,25 +22,18 @@ namespace Ocelot.AcceptanceTests
.AddJsonFile("configuration.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
Config = builder.Build();
}
public IConfigurationRoot Configuration { get; }
public static IConfiguration Config { get; private set; }
public void ConfigureServices(IServiceCollection services)
{
Action<ConfigurationBuilderCachePart> settings = (x) =>
{
x.WithDictionaryHandle();
};
services.AddOcelot(Configuration).AddStoreOcelotConfigurationInConsul();
services.AddOcelot(Config).AddStoreOcelotConfigurationInConsul();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
public void Configure(IApplicationBuilder app)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
app.UseOcelot().Wait();
}
}

View File

@ -0,0 +1,29 @@
using CacheManager.Core;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Ocelot.DependencyInjection;
using Ocelot.AcceptanceTests.Caching;
namespace Ocelot.AcceptanceTests
{
public class StartupWithConsulAndCustomCacheHandle : AcceptanceTestsStartup
{
public StartupWithConsulAndCustomCacheHandle(IHostingEnvironment env) : base(env) { }
public override void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(Configuration)
.AddCacheManager((x) =>
{
x.WithMicrosoftLogging(log =>
{
log.AddConsole(LogLevel.Debug);
})
.WithJsonSerializer()
.WithHandle(typeof(InMemoryJsonHandle<>));
})
.AddStoreOcelotConfigurationInConsul();
}
}
}

View File

@ -0,0 +1,28 @@
using CacheManager.Core;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Ocelot.DependencyInjection;
using Ocelot.AcceptanceTests.Caching;
namespace Ocelot.AcceptanceTests
{
public class StartupWithCustomCacheHandle : AcceptanceTestsStartup
{
public StartupWithCustomCacheHandle(IHostingEnvironment env) : base(env) { }
public override void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(Configuration)
.AddCacheManager((x) =>
{
x.WithMicrosoftLogging(log =>
{
log.AddConsole(LogLevel.Debug);
})
.WithJsonSerializer()
.WithHandle(typeof(InMemoryJsonHandle<>));
});
}
}
}

View File

@ -118,7 +118,7 @@ namespace Ocelot.AcceptanceTests
});
_ocelotServer = new TestServer(_webHostBuilder
.UseStartup<Startup_WithCustomCacheHandle>());
.UseStartup<StartupWithCustomCacheHandle>());
_ocelotClient = _ocelotServer.CreateClient();
}
@ -148,7 +148,7 @@ namespace Ocelot.AcceptanceTests
});
_ocelotServer = new TestServer(_webHostBuilder
.UseStartup<Startup_WithConsul_And_CustomCacheHandle>());
.UseStartup<StartupWithConsulAndCustomCacheHandle>());
_ocelotClient = _ocelotServer.CreateClient();
}