Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark 6 posts 28 karma points
    Dec 19, 2014 @ 11:42
    Mark
    1

    ApplicationStarted not firing

    Using Umbraco 7.2 - created the following class in app_code, but the log entries never appear, and attach to process reveals no activity. Any help would be much appreciated :)

    public class RegisterEvents : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            LogHelper.Debug(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                "#debug1: ApplicationStarted");
    
            ContentService.Saved += ContentSaved;
        }
    
        private void ContentSaved(IContentService sender, 
            Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
        {
            LogHelper.Debug(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                "#debug1: ContentSaved");
        }
    

     

  • Mark 6 posts 28 karma points
    Dec 19, 2014 @ 11:51
    Mark
    0

    I've also tried this, but still no luck:

     

    public class RegisterEvents : IApplicationEventHandler

    {

        public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)

        {

            LogHelper.Debug(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,

                "#debug1: OnApplicationInitialized");

        }

     

    To be clear I'm looking in the umbracoLog table for results

  • Mark 6 posts 28 karma points
    Dec 19, 2014 @ 12:32
    Mark
    1

    Finally got this working. Looking in the wrong place for the log was one issue :p

    For the record: this code works

    public class RegisterEvents : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //#debug - this logs to /App_Data/Logs/UmbracoTraceLog.txt
            //LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
            //    "#debug1: ApplicationStarted", new Exception("#ex1"));
    
            ContentService.Saved += ContentSaved;
        }
    
        private void ContentSaved(IContentService sender, 
            Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
        {
            //#debug
            //LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
            //    "#debug11: ContentSaved", new Exception("#ex11"));
    
            //calculate and save vat
            int contentId = e.SavedEntities.First().Id;
            //etc
        }
    }
  • David Conlisk 432 posts 1008 karma points
    Apr 17, 2015 @ 12:34
    David Conlisk
    0

    Thanks @Mark, I've seen many ways of doing this and this one is the first one that's worked for me, so thanks for sharing :)

Please Sign in or register to post replies

Write your reply to:

Draft