Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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.

share|improve this answer
    
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 May 20 '10 at 15:00
up vote 0 down vote accepted

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?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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