Copied to clipboard

Flag this post as spam?

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


  • Russell McGinnis 48 posts 183 karma points
    Jul 31, 2014 @ 20:33
    Russell McGinnis
    0

    ApplicationStarting not Firing

    I have defined a simple class to handle the ApplicationStarting event in order to wire up a 404 handler as follows:

     

    public class MyApplication : ApplicationEventHandler {

        protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) {

            ContentLastChanceFinderResolver.Current.SetFinder(new _404NewsFinder());

            base.ApplicationStarting(umbracoApplication, applicationContext);

        }

    }

    I have defined this class within the App_Code section of my website and I have also created it within a Class library and added the DLL to my website's BIN folder. Neither causes the ApplicationStarting event in my class to be fired.
    I am using Umbraco V7.1.4
    Any ideas why or even how I could debug this to see whats happening ?
    Thanks
  • Stefan Kip 1614 posts 4131 karma points c-trib
    Jul 31, 2014 @ 20:40
    Stefan Kip
    0

    How did you check if the ApplicationStarting is being fired or not?

  • Russell McGinnis 48 posts 183 karma points
    Jul 31, 2014 @ 20:48
    Russell McGinnis
    0

    Via the Visual Studio 2013 debugger.

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Jul 31, 2014 @ 21:07
    Stefan Kip
    100

    Debuggers aren't 100% reliable in these kind of situations (app start-up).
    Try to log something in-code so you can check that. Or create a text file in the root of your website (with C#). Maybe it does hit the method...

  • Russell McGinnis 48 posts 183 karma points
    Jul 31, 2014 @ 21:23
    Russell McGinnis
    0

    Thanks, I haven't had such reliability issues in the past with debugging, however I have added Log4net logging and found nothing.

    I suspected that maybe Log4net was not properly started at this point, so I added a call to write to a file and it triggered an access denied message (I didn't provide a path so it tried to write it in the system32 folder) so I shall go from here and see what is going on.

    Thanks for the idea

  • John Hildebrant 14 posts 35 karma points
    Aug 22, 2014 @ 16:41
    John Hildebrant
    0

    I think I have the same issue since I get a 500 error whenever I try to call my API which I had working in a local Umbraco project. Did you have any success? How can I write to the Umbraco log?

  • Russell McGinnis 48 posts 183 karma points
    Aug 22, 2014 @ 17:21
    Russell McGinnis
    0

    John, my circumstances seem a little different in that the event really was firing, but the debugger wasnt catching it.

    To get logging... I add the following "using" statements...

    using log4net;

    using System.Reflection;

    Then I add the following declaration to my class:

    private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    The when I want to log anything I call:

    Log.Error("My error message");

    The log4net logging capabilities provided in Umbraco are great, its worth taking a read.

     

     

  • John Hildebrant 14 posts 35 karma points
    Aug 22, 2014 @ 17:25
    John Hildebrant
    0

    Thank you. Actually I had just figured out the logging. I found you can use the logger by adding 

    using Umbraco.Core.Logging;

    Then in your code:

    LogHelper.Info(this.GetType(), "Your message here");

    I did discover that ApplicationStarting is being called even though the remote debugger in VS does not break on my break points there.

  • John Hildebrant 14 posts 35 karma points
    Aug 22, 2014 @ 17:30
    John Hildebrant
    1

    Actually, it turns out that VS is able to break on my break points there. I had to start the debugger then update web.config in order to catch the application restarting in time.

  • Russell McGinnis 48 posts 183 karma points
    Aug 22, 2014 @ 17:32
    Russell McGinnis
    0

    John, thats a great solution... will try that thanks.

    Russell

Please Sign in or register to post replies

Write your reply to:

Draft