You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.4 KiB
41 lines
1.4 KiB
// Author: Simon Gockner
|
|
// Created: 2020-09-14
|
|
// Copyright(c) 2020 SimonG. All Rights Reserved.
|
|
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using Lib.Logging.Interfaces;
|
|
using Lib.Logging.Loggers.Factories;
|
|
using Lib.Logging.Loggers.Interfaces;
|
|
|
|
namespace Lib.Logging.Loggers
|
|
{
|
|
public class LoggerInitializer : ILoggerInitializer
|
|
{
|
|
private readonly string _logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mystify", "Logs");
|
|
private readonly string _logFileName = $"Mystify_Log_{DateTime.Now:yyyy_MM_dd}_{DateTime.Now:hh_mm_ss}.txt";
|
|
|
|
private readonly ILog _log;
|
|
private readonly IFileLoggerFactory _fileLoggerFactory;
|
|
private readonly IConsoleLoggerFactory _consoleLoggerFactory;
|
|
|
|
public LoggerInitializer(ILog log, IFileLoggerFactory fileLoggerFactory, IConsoleLoggerFactory consoleLoggerFactory)
|
|
{
|
|
_log = log;
|
|
_fileLoggerFactory = fileLoggerFactory;
|
|
_consoleLoggerFactory = consoleLoggerFactory;
|
|
}
|
|
|
|
public bool Init()
|
|
{
|
|
IFileLogger fileLogger = _fileLoggerFactory.Create(_logFilePath, _logFileName);
|
|
_log.AddLogger(fileLogger);
|
|
|
|
IConsoleLogger consoleLogger = _consoleLoggerFactory.Create();
|
|
_log.AddLogger(consoleLogger);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
} |