/// <summary>
 /// Gets the information about a file.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="fileHandle">The file handle.</param>
 /// <returns>The file characteristics, if the file information was retrieved successfully, otherwise null.</returns>
 public override FileCharacteristics GetFileCharacteristics(string fileName, IntPtr fileHandle)
 {
     var fileInfo = new FileInfo(fileName);
     if (fileInfo.Exists)
     {
         return new FileCharacteristics(fileInfo.GetCreationTimeUtc(), fileInfo.GetLastWriteTimeUtc(), fileInfo.Length);
     }
     else
         return null;
 }
 /// <summary>
 /// Gets the information about a file.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="fileStream">The file stream.</param>
 /// <returns>The file characteristics, if the file information was retrieved successfully, otherwise null.</returns>
 public override FileCharacteristics GetFileCharacteristics(string fileName, FileStream fileStream)
 {
     if (!string.IsNullOrEmpty(fileName))
     {
         var fileInfo = new FileInfo(fileName);
         if (fileInfo.Exists)
         {
             return new FileCharacteristics(fileInfo.GetCreationTimeUtc(), fileInfo.GetLastWriteTimeUtc(), fileInfo.Length);
         }
     }
     return null;
 }
示例#3
0
        public DateTime? GetFileCreationTimeUtc(string filePath, bool fallback)
        {
            var appender = GetAppender(filePath);
            DateTime? result = null;
            if (appender != null)
            {
                try
                {
                    result = appender.GetFileCreationTimeUtc();
                }
                catch (Exception ex)
                {
                    InternalLogger.Error(ex, "Failed to get file creation time for file '{0}'.", appender.FileName);
                    InvalidateAppender(appender.FileName);
                    throw;
                }
            }                
            if (result == null && fallback)
            {
                var fileInfo = new FileInfo(filePath);
                if (fileInfo.Exists)
                {
                    return fileInfo.GetCreationTimeUtc();
                }
            }

            return result;
        }
示例#4
0
        public DateTime? GetFileCreationTimeUtc(string filePath, bool fallback)
        {
            var appender = GetAppender(filePath);
            DateTime? result = null;
            if (appender != null)
                result = appender.GetFileCreationTimeUtc();
            if (result == null && fallback)
            {
                var fileInfo = new FileInfo(filePath);
                if (fileInfo.Exists)
                {
                    return fileInfo.GetCreationTimeUtc();
                }
            }

            return result;
        }
 /// <summary>
 /// Gets the creation time for a file associated with the appender. The time returned is in Coordinated Universal 
 /// Time [UTC] standard.
 /// </summary>
 /// <returns>The file creation time.</returns>
 public override DateTime? GetFileCreationTimeUtc()
 {
     FileInfo fileInfo = new FileInfo(FileName);
     if (fileInfo.Exists)
     {
         return fileInfo.GetCreationTimeUtc();
     }
     return null;
 }