Hi,
I have an app, written in c#, that checks an email inbox (using
cdo/mapi) and does some processing.
I've written a function "WriteToLogFile (string text, bool onConsole)"
that checks whether the logfile exists (creates it if not), appends
the text to the file, closes the file and displays it on the console,
if required. It uses StreamWriter to accomplish this.
There is another function "CheckEmail()" that logs into the email
account, processes the email and logs out.
The program does what I want, except it can't append to the log file
after a it logs into the email account. Displaying on the Console
_always_ works.
I'll show some pseudo code to explain it better:
Main()
{
WriteToLogFile("1 start Main", true);
CheckEmail();
WriteToLogFile("8 end Main", true);
}
CheckMail()
{
WriteToLogFile("2 start CheckMail", true);
// log on to email account
Object vEmpty = Missing.Value;
Session oSession = new Session();
WriteToLogFile("3 b4 logon", true);
// \/ \/ \/ these get commented out later
oSession.Logon(strProfileName, strProfilePassword, vEmpty, true,
vEmpty, vEmpty, vEmpty);
WriteToLogFile("4 aft logon", true);
// do some stuff...
WriteToLogFile("5 logging off...", true);
oSession.Logoff();
// ^^^ these get commented out later on
WriteToLogFile("6 ...gone", true);
WriteToLogFile("7 end CheckMail", true);
}
I hope that makes sense to you.
The console displays everything you'd expect:
1 start Main
2 start CheckMail
3 b4 logon
4 aft logon
5 logging off...
6 ...gone
7 end CheckMail
8 end Main
but the log file only displays:
1 start Main
2 start CheckMail
3 b4 logon
If I don't logon and process the emails, the log file works again:
1 start Main
2 start CheckMail
3 b4 logon
7 end CheckMail
8 end Main
To my mind, it would seem that when I open a session the StreamWriter
fails to work.
Does anybody know that I'm doing wrong or how to fix it?
PS I'm using .NET v1.1.4322, CDO 1.2.1 on a Win 2K machine connecting
to an exchange server.
Cheers,
Grahame