activities logging

  • Thread starter Thread starter Stanley Cheung
  • Start date Start date
S

Stanley Cheung

hi all,

I want to implement logging for a mailinglist application.
the mailinglist will auto send out from a queuing table and user want to
know the updated status for how many emails have sent.

here is my ideas:
===================================
try
{
// sendemail code
SmtpMail.SmtpServer = "your mail server name goes here";
SmtpMail.Send(Message);
//logged into log file (xxx.log) with datetime
}
catch (Exception ex)
{
//logged description of ex.ToString() into log file (xxx.log) with
datetime
}
===================================
otherwise, can I use NSpring for my above requirement?
http://www.codeproject.com/csharp/nspring.asp

Thanks in advanced.
steambun
 
You mention a queuing table, is that a database table, a message queue or
soemthing completely different? If it is a database table, one option is to
have a trigger on the table that logs a entry to a log table when you remove
entries from the queuing table after sending it. Then you can produce a
report based on the entries in the queuing table and the entries in the log
table. That's one way, anyway...
 
yes, it is database table,
the table has a flag to define the mail sent or not sent..

what do u means log table.... is txt/log file??

Thanks.
 
Use the Trace classes

You can log to any /listener/ which can include a text file.

You can specify a trace file in the app.config or web.config file

Then you just do a Trace.WriteLine()

What I do for my logs is to create a static method, in a class
accessible everywhere in the namespace that does the logging.
Then I can call it at any point. And I include a DateTime.Now stamp.

log(string s)
{
Trace.WriteLine(DateTime.Now + " " + s);
}

I even use reflection for error logs to expose the calling method
automatically and write that to the log.
 
Johns method is certainly a very valid way of doing this, but depending on
your reporting needs, if any, you might want to update the flag in the
table, once your message has been sent. A stored procedure would be a good
choice IMHO.
 
Back
Top