1

I'm hosting an ASP.NET Core app in a Windows Azure Web Site. I'm wondering how to get details of an exception occuring in the Startup.Configure() method? All I see is An error occurred while starting the application..

One thing that DOES work is adding an app setting of ASPNETCORE_ENVIRONMENT="Development". Then I get System.Exception... at X.Startup.Configure() as expected.

But this is not a feasible solution. Azure is my Staging environment, and I'm already using the environment concept to substitute my connection strings (as suggested in almost every ASP.NET Core documentation I have ever read).

Things I have tried without any effect:

Is there really no other way to achieve this, than hijacking the environment concept altogether?

Community
  • 1
  • 1
MEMark
  • 1,493
  • 2
  • 22
  • 32
  • Have you seen this: http://stackoverflow.com/questions/29518365/how-to-get-error-details-of-an-asp-net-5-app-deployed-on-azure-websites?rq=1 ? – tymtam Oct 25 '16 at 23:26
  • Maybe there is a way to implement it self using try...catch `try {...} catch (Exception ex) { var file = env.ContentRootPath+@"\wwwroot\startuperr.htm"; using (FileStream fs = new FileStream(file, FileMode.Append, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine( DateTime.UtcNow+":"+ex.Message + ex.StackTrace); } }` – Tom Sun - MSFT Oct 26 '16 at 09:45
  • @TomSun Thanks, that could be a work-around if all else fails. – MEMark Oct 26 '16 at 12:07

1 Answers1

1

I don't know if this would work for you, but we've decided to report these using Application Insights.

public void Configuration(IAppBuilder app)
{
    var ai = new Microsoft.ApplicationInsights.TelemetryClient();
    ai.TrackEvent("Application Starts");

    try
    {
    //Amazing code here
    }
    catch ( Exception ex )
    {
        ex = new Exception("Application start up failed.", ex);

        ai.TrackException(ex);
        throw;
    }
}
tymtam
  • 31,798
  • 8
  • 86
  • 126