Page 1 of 1

Custom Timed Events

Posted: Thu Jul 11, 2013 8:16 am
by jguengerich
I would like to set up a timed event, so I followed the instructions here: http://wiki.ablecommerce.com/index.php/ ... med_Events.

I set up a variable:

Code: Select all

private System.Threading.Timer _timer2;
I initialized it in Application_Start:

Code: Select all

    _timer2 = new System.Threading.Timer(new System.Threading.TimerCallback(TimedEvent), null, 60000, 60000);
I modified the TimedEvent code to work in Gold (I think), so it looks like the following:

Code: Select all

private void TimedEvent(Object stateInfo)
{
    // THIS IS RUNNING ON ITS OWN THREAD, OUTSIDE OF HTTPCONTEXT
    // (HTTPCONTEXT.CONTEXT IS NULL)
    // YOU MUST INITIALIZE THE TOKEN FOR THE STORE, CHANGE THE ID IF IT IS OTHER THAN 1
    Store store = StoreDataSource.Load(1);
    // INITIALIZE THE TOKEN FOR THIS STORE
    // Token.Instance.InitStoreContext(store);
    AbleContext.Current.Store = store;
    // *********
    // PUT YOUR CODE BELOW THIS COMMENT
    // *********
    Logger.Info("Timed task is running...");
    // *********
    // PUT YOUR CODE ABOVE THIS COMMENT
    // *********
    // RESET THE TOKEN INSTANCE AFTER THE EVENT RUNS
    // Token.ResetInstance();
    AbleContext.Current.Store = null;
}
I do not get any entries in the app.log file, so I have the following questions:
1. Did I modify the code correctly for Gold?
2. What else do I need to do to get this to work?

Re: Custom Timed Events

Posted: Mon Jul 15, 2013 11:52 am
by jguengerich
Actually the code I posted works. However, Logger.Info() doesn't add entries to the app.log file. Use Logger.Error() to create an entry in the app.log file.

Re: Custom Timed Events

Posted: Mon Jul 15, 2013 5:53 pm
by ForumsAdmin
Check App_Data/log4net.config for setting up the logging level. The default level is "WARN". You can set it to "DEBUG" or "INFO".