Example #1
0
 public void Dispose()
 {
     _logger.Dispose();
     _fileLog?.Dispose();
     _consoleLog.Dispose();
     _fileSystem.Dispose();
 }
Example #2
0
 public void Dispose()
 {
     _log.Dispose();
     Console.SetOut(_sdoutWriter); // get back to write to the console
     File.Delete(_testFile);
     GC.SuppressFinalize(this);
 }
Example #3
0
 public void Dispose()
 {
     // 1. it's important to dispose _logger before log objects
     //    because _logger.Dispose() calls Flush() on its log objects
     // 2. it's important to dispose _csvFileLogger before _kustoUploader because
     //    csvFileLogger.Dispose() can post one last file to be uploaded to Kusto
     // 3. it's important to dispose _kustoUploader before _consoleLog because
     //    _kustoUploader uses _consoleLog
     _logger.Dispose();
     _fileLog?.Dispose();
     _csvFileLog?.Dispose();
     _kustoUploader?.Dispose();
     _consoleLog.Dispose();
     _fileSystem.Dispose();
 }
Example #4
0
        private static async Task WithLoggerAsync(Func <ILogger, Task> action, string?logFilePath)
        {
            CsvFileLog?csvFileLog = null;
            ConsoleLog?consoleLog = null;
            Logger?    logger     = null;

            try
            {
                if (!string.IsNullOrEmpty(logFilePath))
                {
                    // Needed to satisfy the type checker
                    Contract.AssertNotNull(logFilePath);

                    if (string.IsNullOrEmpty(Path.GetDirectoryName(logFilePath)))
                    {
                        var cwd = Directory.GetCurrentDirectory();
                        logFilePath = Path.Combine(cwd, logFilePath);
                    }

                    csvFileLog = new CsvFileLog(logFilePath, new List <CsvFileLog.ColumnKind>()
                    {
                        CsvFileLog.ColumnKind.PreciseTimeStamp,
                        CsvFileLog.ColumnKind.ProcessId,
                        CsvFileLog.ColumnKind.ThreadId,
                        CsvFileLog.ColumnKind.LogLevel,
                        CsvFileLog.ColumnKind.LogLevelFriendly,
                        CsvFileLog.ColumnKind.Message,
                    });
                }

                consoleLog = new ConsoleLog(useShortLayout: false, printSeverity: true);

                var logs = new ILog?[] { csvFileLog, consoleLog };
                logger = new Logger(logs.Where(log => log != null).Cast <ILog>().ToArray());

                await action(logger);
            }
            finally
            {
                logger?.Dispose();
                csvFileLog?.Dispose();
                consoleLog?.Dispose();
            }
        }
Example #5
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    _scheduler?.Dispose();
                    _schedulerLogWriter?.Dispose();
                    _alertNotifier?.Dispose();
                    _kustoIngestClient?.Dispose();
                    _cslQueryProvider?.Dispose();
                    _logger?.Dispose();
                    _csvFileLog?.Dispose();
                    _consoleLog?.Dispose();
                }

                _disposedValue = true;
            }
        }
Example #6
0
 public void Dispose()
 {
     _log.Dispose();
     Console.SetOut(_sdoutWriter); // get back to write to the console
     File.Delete(_testFile);
 }