summaryrefslogtreecommitdiff
path: root/tutorial/netstd
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2019-03-14 21:12:38 +0100
committerJens Geyer <jensg@apache.org>2019-03-15 22:01:37 +0100
commitb11f63c552b8ad47b23931177987ada0a92188cf (patch)
tree5e9dee03ffb9377538b3498764c948c82c621238 /tutorial/netstd
parent0c4e96f956cd7e3dc527ef215b14c0407148f46c (diff)
downloadthrift-b11f63c552b8ad47b23931177987ada0a92188cf.tar.gz
THRIFT-4824 Logger deprecation warnings in tutorial
Client: netstd Patch: Jens Geyer this closes #1760
Diffstat (limited to 'tutorial/netstd')
-rw-r--r--tutorial/netstd/Client/Program.cs14
-rw-r--r--tutorial/netstd/Server/Program.cs23
2 files changed, 31 insertions, 6 deletions
diff --git a/tutorial/netstd/Client/Program.cs b/tutorial/netstd/Client/Program.cs
index bf35746e3..4b68cee4a 100644
--- a/tutorial/netstd/Client/Program.cs
+++ b/tutorial/netstd/Client/Program.cs
@@ -31,12 +31,14 @@ using Thrift.Transport;
using Thrift.Transport.Client;
using tutorial;
using shared;
+using Microsoft.Extensions.DependencyInjection;
namespace Client
{
public class Program
{
- private static readonly ILogger Logger = new LoggerFactory().AddConsole().AddDebug().CreateLogger(nameof(Client));
+ private static ServiceCollection ServiceCollection = new ServiceCollection();
+ private static ILogger Logger;
private static void DisplayHelp()
{
@@ -75,6 +77,9 @@ Sample:
{
args = args ?? new string[0];
+ ServiceCollection.AddLogging(logging => ConfigureLogging(logging));
+ Logger = ServiceCollection.BuildServiceProvider().GetService<ILoggerFactory>().CreateLogger(nameof(Client));
+
if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase)))
{
DisplayHelp();
@@ -89,6 +94,13 @@ Sample:
}
}
+ private static void ConfigureLogging(ILoggingBuilder logging)
+ {
+ logging.SetMinimumLevel(LogLevel.Trace);
+ logging.AddConsole();
+ logging.AddDebug();
+ }
+
private static async Task RunAsync(string[] args, CancellationToken cancellationToken)
{
var numClients = GetNumberOfClients(args);
diff --git a/tutorial/netstd/Server/Program.cs b/tutorial/netstd/Server/Program.cs
index 1d9dd1584..d27e90d24 100644
--- a/tutorial/netstd/Server/Program.cs
+++ b/tutorial/netstd/Server/Program.cs
@@ -41,12 +41,17 @@ namespace Server
{
public class Program
{
- private static readonly ILogger Logger = new LoggerFactory().AddConsole(LogLevel.Trace).AddDebug(LogLevel.Trace).CreateLogger(nameof(Server));
+ private static ServiceCollection ServiceCollection = new ServiceCollection();
+ private static ILogger Logger;
public static void Main(string[] args)
{
args = args ?? new string[0];
+ ServiceCollection.AddLogging(logging => ConfigureLogging(logging));
+ Logger = ServiceCollection.BuildServiceProvider().GetService<ILoggerFactory>().CreateLogger(nameof(Server));
+
+
if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase)))
{
DisplayHelp();
@@ -66,6 +71,13 @@ namespace Server
Logger.LogInformation("Server stopped");
}
+ private static void ConfigureLogging(ILoggingBuilder logging)
+ {
+ logging.SetMinimumLevel(LogLevel.Trace);
+ logging.AddConsole();
+ logging.AddDebug();
+ }
+
private static void DisplayHelp()
{
Logger.LogInformation(@"
@@ -131,12 +143,10 @@ Sample:
private static async Task RunSelectedConfigurationAsync(Transport transport, Protocol protocol, CancellationToken cancellationToken)
{
- var fabric = new LoggerFactory().AddConsole(LogLevel.Trace).AddDebug(LogLevel.Trace);
var handler = new CalculatorAsyncHandler();
ITAsyncProcessor processor = null;
TServerTransport serverTransport = null;
-
switch (transport)
{
case Transport.Tcp:
@@ -209,6 +219,7 @@ Sample:
Logger.LogInformation(
$"Selected TAsyncServer with {serverTransport} transport, {processor} processor and {inputProtocolFactory} protocol factories");
+ var fabric = ServiceCollection.BuildServiceProvider().GetService<ILoggerFactory>();
var server = new TSimpleAsyncServer(processor, serverTransport, inputProtocolFactory, outputProtocolFactory, fabric);
Logger.LogInformation("Starting the server...");
@@ -288,8 +299,11 @@ Sample:
.UseUrls("http://localhost:9090")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
+ .ConfigureLogging((ctx,logging) => ConfigureLogging(logging))
.Build();
+ Logger.LogTrace("test");
+ Logger.LogCritical("test");
host.RunAsync(cancellationToken).GetAwaiter().GetResult();
}
@@ -315,8 +329,7 @@ Sample:
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env,
- ILoggerFactory loggerFactory)
+ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseMiddleware<THttpServerTransport>();
}