コード例 #1
0
 public TextWriterLogOutput(TextWriter target, TextLogOutputConfig config)
 {
     _target = target;
     _config = config ?? new TextLogOutputConfig();
     if (_config.LogRotate)
     {
         _logRotator = new LogRotator(config);
     }
 }
コード例 #2
0
 public LogRotator(TextLogOutputConfig config)
 {
     _config        = config;
     _observedFiles = new Stack <FileInfo>();
     CreateLogScheduler();
 }
コード例 #3
0
ファイル: Logs.cs プロジェクト: belzecue/ConsoleXT
        /// <summary>
        /// Initializes a global logfile using the specified target directory and file name
        /// using default settings. If not specified otherwise, a Logs directory is used and
        /// the log file's name is derived from the current <see cref="DateTime"/>.
        /// </summary>
        public static TextWriterLogOutput InitGlobalLogFile(string directory = null, string fileName = null, TextLogOutputConfig config = null)
        {
            // In case someone calls this multiple times, shut down the old one
            ShutdownTextLog();

            try
            {
                // Open a writable stream to the desired, default or fallback log file location
                string loggingPath;
                if (!TryCreateLogStream(directory, fileName, out _textFileLogWriter, out loggingPath))
                {
                    Logs.Default.WriteWarning("Text Logfile unavailable, because no logging location was accessible.");
                    return(null);
                }

                config.LoggingPath = loggingPath;
                // Create, configure and register a log output using the log stream
                _textFileLogOutput = new TextWriterLogOutput(_textFileLogWriter, config);
                Logs.AddGlobalOutput(_textFileLogOutput);
                return(_textFileLogOutput);
            }
            catch (Exception e)
            {
                Logs.Default.WriteWarning("Failed to create text logfile: {0}", LogFormat.Exception(e));
                return(null);
            }
        }