From 76c77f101a3e6d3ecc8664e46c65199a41adc07e Mon Sep 17 00:00:00 2001 From: Richard Terris Date: Sun, 14 Aug 2016 14:01:24 +0100 Subject: [PATCH] Update Logging.md Additional info for enabling logging when writing unit tests --- docsv2/configuration/logging.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docsv2/configuration/logging.md b/docsv2/configuration/logging.md index 7a17f09..f6d9fc9 100644 --- a/docsv2/configuration/logging.md +++ b/docsv2/configuration/logging.md @@ -106,3 +106,16 @@ For certain scenarios (e.g. production) you want to make sure that no logging ou ```csharp LogProvider.SetCurrentLogProvider(new NoopLogProvider()); ``` +## Unit Testing +When writing unit tests, you may want to enable logging to help with debugging, as some errors aren't too detailed (such as getting a 500 error back as the Token Response, for example - this could be a number of things). +Assuming that your unit tests are in a separate project from your Statup class where you register and initialiase your logger, then you will find that logging won't work. +In order to make logging work you will have to wrap the code which makes requests to IdentityServer in a using statment such as: +```csharp + using (var logger = new LoggerConfiguration() + .MinimumLevel.Debug() + .WriteTo.File(@"C:\idsLogs.txt") + .CreateLogger()) + { + var tokenResponse = tokenClient.RequestClientCredentialsAsync("applicationLogin").Result; + } + ```