58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|
{
|
|
public class InMemoryLogger : ILogger, IDisposable
|
|
{
|
|
LogLevel _logLevel = 0;
|
|
|
|
public InMemoryLogger(LogLevel logLevel = LogLevel.Debug)
|
|
{
|
|
_logLevel = logLevel;
|
|
}
|
|
|
|
List<LogEntry> _logEntries = new List<LogEntry>();
|
|
|
|
public IDisposable BeginScopeImpl(object state)
|
|
{
|
|
return this;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public bool IsEnabled(LogLevel logLevel)
|
|
{
|
|
return (logLevel >= _logLevel);
|
|
}
|
|
|
|
public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
|
|
{
|
|
if (IsEnabled(logLevel))
|
|
{
|
|
var logEntry =
|
|
new LogEntry
|
|
{
|
|
EventId = eventId,
|
|
Exception = exception,
|
|
Formatter = formatter,
|
|
Level = logLevel,
|
|
State = state,
|
|
};
|
|
|
|
_logEntries.Add(logEntry);
|
|
Debug.WriteLine(logEntry.ToString());
|
|
}
|
|
}
|
|
|
|
public List<LogEntry> Logs { get { return _logEntries; } }
|
|
}
|
|
}
|