예제 #1
0
        internal Logger(string logFile, LoggerSetup loggerSetup, string configFile)
        {
            this._logFile     = logFile;
            this._loggerSetup = loggerSetup;

            this._queueWaitHandle             = new AutoResetEvent(false);
            this._queue                       = new Queue <string>();
            this._consumerThread              = new Thread(this.ConsumerThread);
            this._consumerThread.IsBackground = true;
            this._consumerThread.Start();

            if (!this.IsNullOrWhiteSpace(configFile))
            {
                this._configFile = LogConfigManager.GetFileFullPath(configFile);

                try
                {
                    this._configFileWatcher = new FileSystemWatcher(Path.GetDirectoryName(this._configFile), Path.GetFileName(this._configFile));
                    this._configFileWatcher.EnableRaisingEvents = true;
                    this._configFileWatcher.NotifyFilter        = NotifyFilters.LastWrite | NotifyFilters.FileName;
                    this._configFileWatcher.Changed            += (s, e) => this._isConfigFileChanged = true;
                    this._configFileWatcher.Created            += (s, e) => this._isConfigFileChanged = true;
                    this._configFileWatcher.Deleted            += (s, e) => this._isConfigFileChanged = true;
                    this._configFileWatcher.Renamed            += (s, e) => this._isConfigFileChanged = true;
                }
                catch (Exception e)
                {
                    InternalLogger.Log(e);
                }
            }

            this.InitFileAppender();

            this.WatchConfigFileChanged();
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MutexMultiProcessFileAppender" /> class.
        /// </summary>
        /// <param name="filename">File to write.</param>
        /// <param name="loggerSetup">Log setup.</param>
        public MutexMultiProcessFileAppender(string filename, LoggerSetup loggerSetup)
        {
            try
            {
                this._fileName = LogConfigManager.GetFileFullPath(filename);

                this._directoryName = Path.GetDirectoryName(this._fileName);

                this._fileInfo = new FileInfo(this._fileName);

                this._loggerSetup = loggerSetup;

                this._mutex = this.CreateSharedMutex(this.GetMutexName(this._fileName));
            }
            catch (Exception e)
            {
                if (this._mutex != null)
                {
                    this._mutex.Close();

                    this._mutex = null;
                }

                InternalLogger.Log(e);

                throw;
            }
        }
예제 #3
0
 /// <summary>
 /// Serves as a hash function for LogConfig instance.
 /// </summary>
 /// <returns>A hash code for the current LogConfig.</returns>
 public override int GetHashCode()
 {
     return(string.Format(
                "{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}",
                LogConfigManager.GetFileFullPath(this.LogFile).ToLowerInvariant(),
                this.LoggerSetup.DateTimeFormat ?? string.Empty,
                this.LoggerSetup.Level.ToString(),
                this.LoggerSetup.WriteToConsole.ToString(),
                this.LoggerSetup.WriteToFile.ToString(),
                this.LoggerSetup.UseBracket.ToString(),
                this.LoggerSetup.EnableStackInfo.ToString(),
                this.LoggerSetup.RollingFileSizeLimit.ToString(),
                this.LoggerSetup.RollingFileCountLimit.ToString(),
                this.LoggerSetup.RollingByDate.ToString()).GetHashCode());
 }