From: Armin Zingler on
Am 11.06.2010 04:44, schrieb mp:
>>> according to online elearning (ms)
>>> to write to a debug log use the following:
>>> 'd. FileInfo fi = new FileInfo(@"c:\application.log");
>>>
>>> ' StreamWriter sw = fi.AppendText();
>>>
>>> I can't seem to convert that to vb successfully
>>>
>>> Dim fi As FileInfo = New FileInfo(m_DebugFileName)
>>
>> Did you
>> import System.IO
>> ?
>
> yes, otherwise the error would have been missing reference or something?

yes, something. You didn't write what the problem was, so I guessed. :)


>> Or, if you just want to open, write, close a/to a file:
>>
>> File.AppendAllText(Path, "abc", System.Text.Encoding.Default)
>>
>>
>
> Hi Armin,
> That last line is how i've been doing it previously.
> when the elearning lesson said it should be the other way i thought i'd try
> that.

Probably because the question was how to _create_ the log file, not how
to write into it. File.AppendAllText above opens, writes, closes the file.
For logging I'd prefer File.AppendAllText because, if the app crashes,
the write buffer hasn't been flushed to disk. Therefore some content
is missing, which is not helpful for logging, maybe for finding errors.
(but that was not the "e-learning question".)


> '
> 'Start e-learning question
>
> '******************
>
> 'You are developing a logging module for a large application by using the
>
> '.NET Framework.
>
> 'You need to append logging information to a file named application.log.
> This
>
> 'log file is opened when the application is started and is closed only when
>
> 'the application is closed. However, you append text several times to the
>
> 'file during a session.
>
> 'You must minimize overhead to the logging process to ensure maximum
>
> 'performance.
>
> 'Which code segment should you use to create the log file?
>
> 'a. StreamWriter sw = File.CreateText(@"c:\application.log");
>
> 'b. FileInfo fi = new FileInfo(@"c:\application.log");
>
> ' FileStream fs = fi.Open(FileMode.Append);
>
> 'c. StreamWriter sw = File.AppendText(@"c:\application.log");
>
> 'd. FileInfo fi = new FileInfo(@"c:\application.log");
>
> ' StreamWriter sw = fi.AppendText();
>
>
>
> it said the correct answer was d.



> ps, what is the meaning of @ in those arguments?

If I enter it in the help index, it finds "@ (string literal)"


--
Armin