/* * Copyright (c) 2023 Proton AG * * This file is part of ProtonVPN. * * ProtonVPN is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProtonVPN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProtonVPN. If not, see . */ using System; using System.Collections.Generic; using System.Linq; using ProtonVPN.Logging.Contracts; namespace ProtonVPN.Dns.Tests.Mocks; public class MockOfLogger : ILogger { private readonly IList _logs = new List(); public IReadOnlyList Logs => _logs as IReadOnlyList; private object _lock = new(); public IList GetRecentLogs() { IList result; lock (_lock) { result = _logs.Select(l => l.Message).ToList(); } return result; } public void Debug( string message, Exception exception = null, int stackTraceDepth = 0, string sourceFilePath = "", string sourceMemberName = "", int sourceLineNumber = 0) where TEvent : ILogEvent, new() { lock (_lock) { _logs.Add(new Log(LogSeverity.Debug, typeof(TEvent), message, exception, sourceFilePath, sourceMemberName, sourceLineNumber)); } } public void Info( string message, Exception exception = null, int stackTraceDepth = 0, string sourceFilePath = "", string sourceMemberName = "", int sourceLineNumber = 0) where TEvent : ILogEvent, new() { lock (_lock) { _logs.Add(new Log(LogSeverity.Info, typeof(TEvent), message, exception, sourceFilePath, sourceMemberName, sourceLineNumber)); } } public void Warn( string message, Exception exception = null, int stackTraceDepth = 0, string sourceFilePath = "", string sourceMemberName = "", int sourceLineNumber = 0) where TEvent : ILogEvent, new() { lock (_lock) { _logs.Add(new Log(LogSeverity.Warn, typeof(TEvent), message, exception, sourceFilePath, sourceMemberName, sourceLineNumber)); } } public void Error( string message, Exception exception = null, int stackTraceDepth = 0, string sourceFilePath = "", string sourceMemberName = "", int sourceLineNumber = 0) where TEvent : ILogEvent, new() { lock (_lock) { _logs.Add(new Log(LogSeverity.Error, typeof(TEvent), message, exception, sourceFilePath, sourceMemberName, sourceLineNumber)); } } public void Fatal( string message, Exception exception = null, int stackTraceDepth = 0, string sourceFilePath = "", string sourceMemberName = "", int sourceLineNumber = 0) where TEvent : ILogEvent, new() { lock (_lock) { _logs.Add(new Log(LogSeverity.Fatal, typeof(TEvent), message, exception, sourceFilePath, sourceMemberName, sourceLineNumber)); } } }