Skip to content

Commit

Permalink
Switch to liblog (#101)
Browse files Browse the repository at this point in the history
Switch to LibLog
  • Loading branch information
smithrobs authored Jul 21, 2018
1 parent 175693c commit 1eab5f7
Show file tree
Hide file tree
Showing 8 changed files with 2,550 additions and 110 deletions.
32 changes: 5 additions & 27 deletions Nexmo.Api/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
using System.Collections.Generic;
using System.Net.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Nexmo.Api.Logging;
using Nexmo.Api.Request;

namespace Nexmo.Api
Expand All @@ -18,22 +17,6 @@ static Configuration()

private Configuration()
{
_serviceProvider = new ServiceCollection()
.AddLogging()
.BuildServiceProvider()
;
var loggerFactory = _serviceProvider.GetService<ILoggerFactory>();

var loggingConfiguration = new ConfigurationBuilder()
.AddJsonFile("logging.json", true, true)
.Build();

loggerFactory.AddConsole(loggingConfiguration);

var configLogger = loggerFactory.CreateLogger<Configuration>();
ApiLogger = loggerFactory.CreateLogger("Nexmo.Api");
AuthenticationLogger = loggerFactory.CreateLogger("Nexmo.Api.Authentication");

var builder = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
Expand Down Expand Up @@ -68,28 +51,23 @@ private Configuration()

if (authCapabilities.Count == 0)
{
configLogger.LogInformation("No authentication found via configuration. Remember to provide your own.");
Logger.Info("No authentication found via configuration. Remember to provide your own.");
}
else
{
configLogger.LogInformation("Available authentication: {0}", string.Join(",", authCapabilities));
Logger.Info("Available authentication: {0}", string.Join(",", authCapabilities));
}
}

private HttpClient _client;
private readonly IServiceProvider _serviceProvider;

internal ILogger ApiLogger;
internal ILogger AuthenticationLogger;

public ILoggerFactory Logger => _serviceProvider.GetService<ILoggerFactory>();
private static readonly ILog Logger = LogProvider.For<Configuration>();

public static Configuration Instance { get; } = new Configuration();

public IConfiguration Settings { get; }

public HttpMessageHandler ClientHandler { get; set; }

private HttpClient _client;
public HttpClient Client
{
get
Expand Down
Loading

0 comments on commit 1eab5f7

Please sign in to comment.