2017-07-20 14:16:47 +02:00
|
|
|
|
/*
|
2018-01-16 08:24:00 +01:00
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
2017-07-20 14:16:47 +02:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Core.Logging
|
|
|
|
|
{
|
2018-03-06 14:35:10 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Wraps an implementation of <see cref="ILogger"/> in order to append information about the module from which messages are logged.
|
|
|
|
|
/// </summary>
|
2017-07-20 14:16:47 +02:00
|
|
|
|
public class ModuleLogger : ILogger
|
|
|
|
|
{
|
|
|
|
|
private ILogger logger;
|
|
|
|
|
private Type module;
|
|
|
|
|
|
|
|
|
|
public ModuleLogger(ILogger logger, Type module)
|
|
|
|
|
{
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.module = module;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 15:33:54 +01:00
|
|
|
|
public void Debug(string message)
|
|
|
|
|
{
|
|
|
|
|
logger.Debug(AppendModuleInfo(message));
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 14:16:47 +02:00
|
|
|
|
public void Error(string message)
|
|
|
|
|
{
|
|
|
|
|
logger.Error(AppendModuleInfo(message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Error(string message, Exception exception)
|
|
|
|
|
{
|
|
|
|
|
logger.Error(AppendModuleInfo(message), exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<ILogContent> GetLog()
|
|
|
|
|
{
|
|
|
|
|
return logger.GetLog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Info(string message)
|
|
|
|
|
{
|
|
|
|
|
logger.Info(AppendModuleInfo(message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Log(string message)
|
|
|
|
|
{
|
|
|
|
|
logger.Log(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Log(ILogContent content)
|
|
|
|
|
{
|
|
|
|
|
logger.Log(content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Subscribe(ILogObserver observer)
|
|
|
|
|
{
|
|
|
|
|
logger.Subscribe(observer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unsubscribe(ILogObserver observer)
|
|
|
|
|
{
|
|
|
|
|
logger.Unsubscribe(observer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Warn(string message)
|
|
|
|
|
{
|
|
|
|
|
logger.Warn(AppendModuleInfo(message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string AppendModuleInfo(string message)
|
|
|
|
|
{
|
|
|
|
|
return $"[{module.Name}] {message}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|