diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-12-28 23:30:23 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-12-28 23:30:23 +0200 |
| commit | 537212b4aa3419d75ce015e5aa3a455288dc430a (patch) | |
| tree | 60779db3e7c42611219a6f858db54aa6450c6eb0 /Software/Visual_Studio/Tango.Web | |
| parent | 00de504d4d276063ec6b732cc95e476c89182df2 (diff) | |
| download | Tango-537212b4aa3419d75ce015e5aa3a455288dc430a.tar.gz Tango-537212b4aa3419d75ce015e5aa3a455288dc430a.zip | |
Implemented Azure Cloud Logger.
Implemented base class for global.asax
Diffstat (limited to 'Software/Visual_Studio/Tango.Web')
3 files changed, 100 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Web/Logging/AzureCloudLogger.cs b/Software/Visual_Studio/Tango.Web/Logging/AzureCloudLogger.cs new file mode 100644 index 000000000..8cdc21d20 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Logging/AzureCloudLogger.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Logging; + +namespace Tango.Web.Logging +{ + /// <summary> + /// Represents an azure blob storage logger. + /// </summary> + /// <seealso cref="Tango.Logging.ILogger" /> + public class AzureCloudLogger : ILogger + { + /// <summary> + /// Initializes a new instance of the <see cref="AzureCloudLogger"/> class. + /// </summary> + public AzureCloudLogger() + { + Enabled = true; + } + + /// <summary> + /// Called when a new log is available. + /// </summary> + /// <param name="log">The log.</param> + public void OnLog(LogItemBase log) + { + switch (log.Category) + { + case LogCategory.Info: + Trace.TraceInformation(log.ToString()); + break; + case LogCategory.Warning: + Trace.TraceWarning(log.ToString()); + break; + case LogCategory.Error: + Trace.TraceError(log.ToString()); + break; + case LogCategory.Critical: + Trace.TraceError(log.ToString()); + break; + case LogCategory.Debug: + Trace.WriteLine(log.ToString()); + break; + } + } + + /// <summary> + /// Gets or sets a value indicating whether this <see cref="T:Tango.Logging.ILogger" /> is enabled. + /// </summary> + public bool Enabled { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj index 70ac28e6e..0f04121d1 100644 --- a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj +++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj @@ -246,8 +246,10 @@ <Compile Include="ActiveDirectory\ActiveDirectoryManager.cs" /> <Compile Include="Authentication\TokensManager.cs" /> <Compile Include="DeploymentSlot.cs" /> + <Compile Include="Logging\AzureCloudLogger.cs" /> <Compile Include="Storage\ExtensionMethods.cs" /> <Compile Include="Storage\StorageManager.cs" /> + <Compile Include="TangoWebApplication.cs" /> <Compile Include="WebConfig.cs" /> <Compile Include="Controllers\JsonController.cs" /> <Compile Include="Formatters\JsonNetFormatter.cs" /> diff --git a/Software/Visual_Studio/Tango.Web/TangoWebApplication.cs b/Software/Visual_Studio/Tango.Web/TangoWebApplication.cs new file mode 100644 index 000000000..c9fea1678 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/TangoWebApplication.cs @@ -0,0 +1,42 @@ +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()); + } + + //common service to be used for logging errors + public static class ErrorLogService + { + public static void LogError(Exception ex) + { + LogManager.Default.Log(ex, "Global Exception!"); + } + } + } +} |
