Beispiel #1
0
        public Logger(IFileAndFolderServices fileAndFolderServices)
        {
            _fileAndFolderServices    = fileAndFolderServices;
            Application.Current.Exit += OnApplicationExit;

            _logFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Andromeda\\Logs";
            _fullLogPath = _logFilePath + "\\" + LogFileName;

            ValidateLogDirectoryExists();

            if (!File.Exists(_fullLogPath))
            {
                _fileAndFolderServices.CreateNewTextFile(_fullLogPath);
            }

            _cancellationToken = new CancellationTokenSource();
            _loggingTask       = Task.Factory.StartNew(ProcessQueue, _cancellationToken.Token);

            LogMessage("Logger initiated.");
        }
Beispiel #2
0
        public Logger(IFileAndFolderServices fileAndFolderServices)
        {
            _fileAndFolderServices = fileAndFolderServices;
            Application.Current.Exit += OnApplicationExit;

            _logFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Logs";
            _fullLogPath = _logFilePath + "\\" + LogFileName;

            ValidateLogDirectoryExists();

            if (!File.Exists(_fullLogPath))
            {
                _fileAndFolderServices.CreateNewTextFile(_fullLogPath);
            }

            var loggingThread = new Thread(new ThreadStart(ProcessQueue));
            loggingThread.IsBackground = true;
            loggingThread.Start();

            LogMessage("Logger initiated.");
        }
Beispiel #3
0
        private void LogFallbackException(Exception exception)
        {
            var fullpath = $"{FallbackLogFilePath}{FallbackLogFileName}";

            if (!Directory.Exists(FallbackLogFilePath))
            {
                Directory.CreateDirectory(FallbackLogFilePath);
            }

            if (!File.Exists(fullpath))
            {
                _fileAndFolderServices.CreateNewTextFile(fullpath);
            }

            var sb = new StringBuilder();

            sb.AppendLine($"[{DateTime.Now}]:LOGGER EXCEPTION MESSAGE:{exception.Message}");
            sb.AppendLine($"[{DateTime.Now}]:STACK TRACE: {exception.StackTrace}");

            _fileAndFolderServices.WriteToTextFile(fullpath, sb.ToString(), this);
        }