How to get error details on Azure Web site
Asked Answered
L

3

28

I'm new to Azure. Does anybody know how get detailed error message on website deployed to Azure web?

I added SimpleMembership to website and now Registration and Login (Post) are showing

Sorry, an error occurred while processing your request.

I'm connecting to DB on my home computer (no problem with connection).

LogFiles folder on azure ftp server has some files but I don't see how to use this information. I wish I can get YellowScreen on azure...

Lui answered 1/11, 2012 at 20:37 Comment(0)
S
27

You have two options:

First, you can turn off custom errors in your web config. This is the quick-and-dirty approach but it will at least get you the information you are looking for. Just be sure to turn custom errors back on when you are done. NOTE: This method will display your stacktrace to the entire world.

<configuration>
  <system.web>
    <customErrors mode="Off" />
  </system.web>
</configuration>

Second, you can remote desktop into your deployed machine, go to IIS Manager, and Browse to your site. Once you are there, reproduce the error and you will get the yellow screen of death you are looking for. For this to work, you will have to Enable Detailed Errors

Spiculum answered 1/11, 2012 at 21:1 Comment(4)
I would list option 2 first, just to stress the fact that disabling custom errors and presenting the stacktrace to the world is generally a bad idea. Remote in or use Azure SDK tools to view events logs from Visual Studio.Batavia
Option 2 would only be available on a VM though right? If you deployed as Azure Websites you don't have access to IIS do you?Chez
I'd expect an area in the old or new portal to show you the errors (well it gives you a count but not details). Basically I am looking for something similar to EventViewerChez
I tried this in our Azure site and it does not enable remote detailed messages. You can use Tools / Streaming logs to observe logs (after you turn them on in settings) but it's slow and unreliable.Intellect
G
0

Create a table in db where you will store you error logs, I'm using EF and table called Logs.

Create a class:

public class MyAppExceptionFilter : IExceptionFilter
    {
        private MyApp.Models.ApplicationDbContext db = new Models.ApplicationDbContext();

        public void OnException(ExceptionContext context)
        {
            Exception ex = context.Exception;
            Log log = new Log();
            log.DateTime = DateTime.Now;
            log.LogText = "Exception happened, text:" + ex.Message;
            try
            {
                log.LogText +="User details:"+context.HttpContext.User.Identity.Name;
            }
            catch
            {
                log.LogText += "User details:none";
            }
            db.Logs.Add(log);
            db.SaveChanges();
        }
    }

In FilterConfig.cs in App_Start folder add:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
            *filters.Add(new MyAppExceptionFilter());*
        }
Goar answered 17/9, 2015 at 10:25 Comment(1)
elmah does a better job of this for free, no point reinventing the wheel. If you pay theres some great solutions out there.Nonexistence
M
0

You can also get the same diagnostic by piping console logs to the cloud shell. Login to azure. Bring up the console...azure CLI.

az webapp log config --name <app-name> --resource-group
myResourceGroup --application-logging filesystem --level information

To start streaming...

az webapp log tail --name <app-name> --resource-group myResourceGroup

Now just refresh the browser for the error.

Ctrl-C back at the CLI will stop streaming.

I picked this up here:Tutorial: Build an ASP.NET Core and Azure SQL Database app in Azure App Service

Marmara answered 4/3, 2021 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.