0

I have a logging module in my solution that adds log entries to a List<>. I’d like to set up a timer that calls a “WriteEntriesToLogFile” method which writes the entries in the List<> to a file on the disk.

Where would be the best place to add this code so whatever page the user is on the method is called at the specified time intervals? Would the global.asax be the right choice? I’m a bit worried that would affect other SharePoint web sites on the same server.

2 Answers 2

1

You may want to consider an HTTP module. This should give you the universal behavior your are looking for. However, this is handling individual requests and not doing anything on a timed basis. Look at a custom timer job if it needs to be on a schedule.

1
  • Agreed- custom timer job deployed via a Feature, so you can enable/disable from Site Settings/Site Features page (if you wanted to).
    – James Love
    Commented May 20, 2010 at 15:00
0

I’ve gone in a slightly different direct and added a timer to the constructor of the Logging class. Something along these lines...

Timer LogTimer = new Timer();
LogTimer.Elapsed += new ElapsedEventHandler(WriteLogEntriesToDisk);
LogTimer.Interval = 5000;
LogTimer.Start();

I’m interested to know what people think, is this a satisfactory solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.