Example #1
0
        public ExternalActionLogger(
            Action<string> writeAction,
            ICommonMessageSettings commonMessageSettings,
            ILogMessageFactory logMessageFactory
            )
        {
            if (writeAction == null)
            {
                throw new ArgumentNullException("writeAction");
            }
            if (commonMessageSettings == null)
            {
                throw new ArgumentNullException("commonMessageSettings");
            }
            if (logMessageFactory == null)
            {
                throw new ArgumentNullException("logMessageFactory");
            }

            _writeAction = writeAction;
            _commonMessageSettings = commonMessageSettings;
            _logMessageFactory = logMessageFactory;

            WriteHead();
        }
 public TextLogFileWrapperFactory(
     ICommonMessageSettings commonMessageSettings
     )
 {
     if (commonMessageSettings == null)
     {
         throw new ArgumentNullException("commonMessageSettings");
     }
     _commonMessageSettings = commonMessageSettings;
 }
Example #3
0
        public TextLogFileWrapper(
            ICommonMessageSettings commonMessageSettings,
            DateTime createDate,
            string filePath,
            LogFileOpenModeEnum fileOpenMode
            )
        {
            if (commonMessageSettings == null)
            {
                throw new ArgumentNullException("commonMessageSettings");
            }
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            _commonMessageSettings = commonMessageSettings;

            CreateDate = createDate;

            _fileInformation = new FileInfo(filePath);

            switch (fileOpenMode)
            {
                case LogFileOpenModeEnum.NoCreate:
                    //nothing to do
                    break;
                case LogFileOpenModeEnum.CreateNew:
                    _fileStream = new FileStream(
                        filePath,
                        FileMode.CreateNew,
                        FileAccess.ReadWrite,
                        FileShare.Read
                        );

                    //write head messages after creating new log file
                    WriteHead();
                    break;
                case LogFileOpenModeEnum.AppendToExisting:
                    _fileStream = new FileStream(
                        filePath,
                        FileMode.Open,
                        FileAccess.ReadWrite,
                        FileShare.Read
                        );

                    _fileStream.Position = _fileStream.Length;

                    //write head messages after opening existing log file
                    WriteHead();
                    break;
                default:
                    throw new ArgumentOutOfRangeException("fileOpenMode");
            }
        }