Files
SGU-CredentialProvider/src/samples/Lithnet.CredentialProvider.Sample.net472.x64/InternalLogger.cs
T
Ryan Newington 1205f217b3 Cleans up static loggers
Adds test projects for different frameworks and architectures
Adds registration tool assembly
2023-01-29 17:30:37 +11:00

37 lines
1.2 KiB
C#

using Microsoft.Extensions.Logging;
using NLog;
using NLog.Extensions.Logging;
namespace Lithnet.CredentialProvider.Samples
{
internal static class InternalLogger
{
internal static ILoggerFactory LoggerFactory { get; }
static InternalLogger()
{
/*
This sample uses NLog to capture trace events from the provider, but you can use any
logging system compatible with Microsoft.Extensions.Logging;
*/
var config = new NLog.Config.LoggingConfiguration();
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
/*
Add file based logging if required
*/
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "c:\\file.txt" };
config.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, logfile);
config.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, logconsole);
LogManager.Configuration = config;
InternalLogger.LoggerFactory = new NLogLoggerFactory(new NLogLoggerProvider(new NLogProviderOptions() { ReplaceLoggerFactory = true }, LogManager.LogFactory));
}
}
}