aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Web/TangoWebApplication.cs
blob: a8acc419c2a5ff94e4fbec43b9be65ceac182db3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Http.Filters;
using System.Web.Mvc;
using Tango.Logging;
using Tango.Web.Logging;

namespace Tango.Web
{
    public class TangoWebApplication : HttpApplication
    {
        //Create filter
        public class LogExceptionFilterAttribute : ExceptionFilterAttribute
        {
            public override void OnException(HttpActionExecutedContext context)
            {
                ErrorLogService.LogError(context.Exception);
            }
        }

        protected virtual void Application_Start()
        {
            LogManager.Default.RegisterLogger(new AzureCloudLogger());
            GlobalConfiguration.Configuration.Filters.Add(new LogExceptionFilterAttribute());
        }

        protected void Application_Error(object sender, EventArgs e)
        {
            Exception exception = Server.GetLastError();
            if (exception != null)
            {
                LogManager.Default.Log(exception, "Global Exception!");
            }
        }

        //common service to be used for logging errors
        public static class ErrorLogService
        {
            public static void LogError(Exception ex)
            {
                LogManager.Default.Log(ex, "Global Exception!");
            }
        }
    }
}