seb-win-refactoring/SafeExamBrowser.ResetUtility/CompositionRoot.cs

63 lines
1.8 KiB
C#

/*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
*
* 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.IO;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Logging;
using SafeExamBrowser.ResetUtility.Procedure;
namespace SafeExamBrowser.ResetUtility
{
internal class CompositionRoot
{
private ILogger logger;
internal ProcedureStep InitialStep { get; private set; }
internal NativeMethods NativeMethods { get; private set; }
internal void BuildObjectGraph()
{
InitializeLogging();
var context = new Context
{
Logger = logger,
};
InitialStep = new Initialization(context);
NativeMethods = new NativeMethods();
}
internal void LogStartupInformation()
{
logger.Log($"# Application started at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
logger.Log(string.Empty);
}
internal void LogShutdownInformation()
{
logger.Log(string.Empty);
logger?.Log($"# Application terminated at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
}
private void InitializeLogging()
{
var appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), nameof(SafeExamBrowser));
var logFolder = Path.Combine(appDataFolder, "Logs");
var logFilePrefix = DateTime.Now.ToString("yyyy-MM-dd\\_HH\\hmm\\mss\\s");
var logFilePath = Path.Combine(logFolder, $"{logFilePrefix}_{nameof(ResetUtility)}.log");
var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), logFilePath);
logger = new Logger();
logger.LogLevel = LogLevel.Debug;
logger.Subscribe(logFileWriter);
logFileWriter.Initialize();
}
}
}