private FileStream TryCreateFileStream(bool allowConcurrentWrite) { FileShare fileShare = FileShare.Read; if (allowConcurrentWrite) { fileShare = FileShare.ReadWrite; } #if !NET_CF if (this.CreateFileParameters.EnableFileDelete && PlatformDetector.GetCurrentRuntimeOS() != RuntimeOS.Windows) { fileShare |= FileShare.Delete; } #endif #if !NET_CF && !SILVERLIGHT if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.WindowsNT) || PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Windows)) { return(this.WindowsCreateFile(this.FileName, allowConcurrentWrite)); } #endif return(new FileStream( this.FileName, FileMode.Append, FileAccess.Write, fileShare, this.CreateFileParameters.BufferSize)); }
/// <summary> /// Initializes file logging by creating data structures that /// enable efficient multi-file logging. /// </summary> protected override void InitializeTarget() { base.InitializeTarget(); if (!this.KeepFileOpen) { this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory; } else { if (this.ArchiveAboveSize != -1 || this.ArchiveEvery != FileArchivePeriod.None) { if (this.NetworkWrites) { this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory; } else if (this.ConcurrentWrites) { #if NET_CF || SILVERLIGHT this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory; #elif MONO // // mono on Windows uses mutexes, on Unix - special appender // if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Unix)) { this.appenderFactory = UnixMultiProcessFileAppender.TheFactory; } else { this.appenderFactory = MutexMultiProcessFileAppender.TheFactory; } #else this.appenderFactory = MutexMultiProcessFileAppender.TheFactory; #endif } else { this.appenderFactory = CountingSingleProcessFileAppender.TheFactory; } } else { if (this.NetworkWrites) { this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory; } else if (this.ConcurrentWrites) { #if NET_CF || SILVERLIGHT this.appenderFactory = RetryingMultiProcessFileAppender.TheFactory; #elif MONO // // mono on Windows uses mutexes, on Unix - special appender // if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Unix)) { this.appenderFactory = UnixMultiProcessFileAppender.TheFactory; } else { this.appenderFactory = MutexMultiProcessFileAppender.TheFactory; } #else this.appenderFactory = MutexMultiProcessFileAppender.TheFactory; #endif } else { this.appenderFactory = SingleProcessFileAppender.TheFactory; } } } this.recentAppenders = new BaseFileAppender[this.OpenFileCacheSize]; if ((this.OpenFileCacheSize > 0 || this.EnableFileDelete) && this.OpenFileCacheTimeout > 0) { this.autoClosingTimer = new Timer( this.AutoClosingTimerCallback, null, this.OpenFileCacheTimeout * 1000, this.OpenFileCacheTimeout * 1000); } // Console.Error.WriteLine("Name: {0} Factory: {1}", this.Name, this.appenderFactory.GetType().FullName); }
/// <summary> /// Initializes file logging by creating data structures that /// enable efficient multi-file logging. /// </summary> public override void Initialize() { base.Initialize(); if (!KeepFileOpen) { _appenderFactory = RetryingMultiProcessFileAppender.TheFactory; } else { if (_archiveAboveSize != -1 || _archiveEvery != ArchiveEveryMode.None) { if (NetworkWrites) { _appenderFactory = RetryingMultiProcessFileAppender.TheFactory; } else if (ConcurrentWrites) { #if NETCF _appenderFactory = RetryingMultiProcessFileAppender.TheFactory; #elif MONO // // mono on Windows uses mutexes, on Unix - special appender // if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Unix)) { _appenderFactory = UnixMultiProcessFileAppender.TheFactory; } else { _appenderFactory = MutexMultiProcessFileAppender.TheFactory; } #else _appenderFactory = MutexMultiProcessFileAppender.TheFactory; #endif } else { _appenderFactory = CountingSingleProcessFileAppender.TheFactory; } } else { if (NetworkWrites) { _appenderFactory = RetryingMultiProcessFileAppender.TheFactory; } else if (ConcurrentWrites) { #if NETCF _appenderFactory = RetryingMultiProcessFileAppender.TheFactory; #elif MONO // // mono on Windows uses mutexes, on Unix - special appender // if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Unix)) { _appenderFactory = UnixMultiProcessFileAppender.TheFactory; } else { _appenderFactory = MutexMultiProcessFileAppender.TheFactory; } #else _appenderFactory = MutexMultiProcessFileAppender.TheFactory; #endif } else { _appenderFactory = SingleProcessFileAppender.TheFactory; } } } _recentAppenders = new BaseFileAppender[OpenFileCacheSize]; if ((OpenFileCacheSize > 0 || EnableFileDelete) && OpenFileCacheTimeout > 0) { _autoClosingTimer = new Timer(new TimerCallback(this.AutoClosingTimerCallback), null, OpenFileCacheTimeout * 1000, OpenFileCacheTimeout * 1000); } // Console.Error.WriteLine("Name: {0} Factory: {1}", this.Name, _appenderFactory.GetType().FullName); }