あるフォルダーから別のフォルダーに 1000 個のファイルをコピーするアプリケーションがあります。各ファイルがコピーされた後、コピーの成功/失敗情報を別のファイルに書き込みます。
このコピー情報をファイルに書き込んでいるときにStreamWriter.WriteLine
、次の例外がスローされる場合があります。
2014 年 10 月 28 日 12.21.02.068 メッセージ : このコマンドを処理するのに十分なストレージがありません。ファイル名 : ファイル C:\Program Files\XYZ\SampleFile.xml を C:\Program Files\ABC\SampleFile.xml.xml にコピーします | 内部例外 : | タイプ: System.IO.IOException | ソース: mscorlib
Not enough storage is available to process this command.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__ConsoleStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.IO.TextWriter.WriteLine(String value)
at System.IO.TextWriter.SyncTextWriter.WriteLine(String value)
at System.Console.WriteLine(String value)
at VersionActivator.VersionActivationController.LogMessage(String message)
mscorlib : Not enough storage is available to process this command.**
ただし、このアプリケーションは、PC がセーフ モードで初期化されている場合に正常に動作します。
私のコード:
foreach (FileInfo fi in source.GetFiles())
{
if (fi.Exists)
{
string destFileName = Path.Combine(target.FullName, fi.Name);
// If the file is readonly, make it non-readonly
if (File.Exists(destFileName))
{
File.SetAttributes(destFileName, FileAttributes.Normal); // IMS 2793051209
}
LogMessage(string.Format("Copying file {0} to {1}", fi.FullName, destFileName));
fi.CopyTo(destFileName, true);
}
}
public void LogMessage(string message)
{
try
{
**Console.WriteLine(message); // This is the place am getting IO exception**
if (m_LogWriter != null)
{
m_LogWriter.WriteLine(
string.Format(@"{0} {1}"
, DateTime.Now.ToString("MM/dd/yyyy HH.mm.ss.fff")
, message)
);
}
}
catch (Exception ex)
{
WriteException(ex, message);
throw;
}
}