event log messages mysteriously disappear ?

i got a problem which some of the event log message does not appear on the event viewer
It could be due to server load or some message is dropped. Can this issue be solved ?
Or is there a better way to do it. See the below source code.and comments.


#region Method : LogEvent
public static void LogEvent(string eventLogSource, string message, int eventID)
{
try
{
System.Diagnostics.EventLog.WriteEntry(eventLogSource,
message,
System.Diagnostics.EventLogEntryType.SuccessAudit,
eventID
);
}
catch( Exception ex )
{
string e = ex.Message;
}
}
#endregion


#region Method : LockPlayer
public bool LockPlayer(zzzTokenData userToken, int playerID)
{
bool update = false;

try
{
...
LogEvent("zzz1",
"Some Message 1", /* message 1 will be retain or lost sometimes */
100);

LogEvent("zzz2",
"Some Message 2", /* message 2 will be lost */
100);

update = true;
}
catch (Exception ex) /* excetion will smtimes also disappear */
{
LogEventError("zzz1",
string.Format("LOCK PLAYER EXCEPTION - membercode:{0} {1} Message:{2}", userToken.MemberCode, System.Environment.NewLine, ex.Message),
100);
}

return (update);
}
#endregion

[1547 byte] By [brohans] at [2007-12-25]
# 1

It's probably an exception being thrown in your LogEvent method. You catch all execptions and simply assing the Message of the exception to a string (string e=ex.Message) you don't use. So basically you just ignore all exceptions.

Try catching the exceptions in the Logevent procedure (and dump them in a log file or something if you don't want to show messagesboxes in a production environment) and see if any exceptions occurs.

Regards,

Sven

SvenDeBont at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2

Hi,

Is your problem solved or do you still need assistance?

Regards,

SvenDeBont at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
no...its not solved. i still need help.
brohans at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4

Did you try to examine if the LogEvent method causes an exception?

In your code, these exceptions will never shown since you simply assign them to a string. If you are using a Windows.Forms application, use a messagebox to show the exception. If you are using a console application, write it to the console. For a class library, you could write it to a file.

#region Method : LogEvent
public static void LogEvent(string eventLogSource, string message, int eventID)
{
try
{
System.Diagnostics.EventLog.WriteEntry(eventLogSource,
message,
System.Diagnostics.EventLogEntryType.SuccessAudit,
eventID
);
}
catch( Exception ex )
{
string e = ex.Message; //change this to something that outputs the exception
}
}
#endregion

SvenDeBont at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified