How can I log user errors and actions in Windows Azure (MVC)?

Azure is changing so fast, so can someone give me some tips on how I could record:

  • Mistakes
  • Exceptions
  • User Actions

I would like to be able to write them to a table repository so that they can be retrieved using code and viewed on administrative web pages. I'm not looking much for code, but I really want to know where I should look. Azure is changing so fast that I want to be sure which is best to use.

thanks

+4
source share
3 answers

I just did something similar on the weekend. I ended up creating 1 table called "LogEvents" and used the provider key to separate the different types of events and log dates (for example, ProviderKey = "20111121_LoginEvent" when someone logged in November 21).

For me, queries can be easily performed by date / type and display the result on the admin page

Not sure if this is the best way, but it seems to work for me. I searched google but couldn't find anything that really did this.


Update 1: The class I'm using is called LogEvent:

public class LogEntry : TableServiceEntity { public LogEntry(string logType) { if (LogType == null || LogType.Length == 0) { if (logType.Length > 0) LogType = logType; else LogType = "Default"; } PartitionKey = string.Format("{0}_{1}", LogType, DateTime.UtcNow.ToString("yyyyMMdd")); RowKey = string.Format("{0:10}_{1}", DateTime.MaxValue.Ticks - DateTime.Now.Ticks, Guid.NewGuid()); } public LogEntry() { } public string Message { get; set; } public DateTime LogDateTime { get; set; } public string LogType { get; set; } } 

I just create a new instance and set the properties:

 LogEntry le = new LogEntry("Default") { Message = "Default Page Loaded", LogDateTime=DateTime.Now }; LogEntryDataSource ds = new LogEntryDataSource(); ds.AddLogEntry(le); 

To return the data again, I just use the standard Linq query and pass in the date and LogType:

  public IEnumerable<LogEntry> GetLogEntries(string eventType, DateTime logDate) { var results = from g in this.context.LogEntry where g.PartitionKey == String.Format("{0}_{1}", eventType, logDate.ToString("yyyyMMdd")) select g; return results; } 

Probably the best way, but it was pretty easy to set up, and it works for me.

-3
source

Azure has a built-in registration and tracking function, see

http://msdn.microsoft.com/en-us/magazine/ff714589.aspx

for more information on this.

Here's how I used Azure diagnostics myself:

code:

 using System; using Microsoft.WindowsAzure.Diagnostics; namespace CrossCuttingConcerns { /// <summary> /// This class handles diagnostics and stores the logs in the Azure table and blog storage. /// Note: Basically all logs are turned on here, this can be expensive and you may want to change several settings here before going live /// </summary> public class AzureDiagnostics { /// <summary> /// Sets how often diagnostics data is transferred to the Azure table storage or blob storage /// Note: Change to a period that fits your need, commenting out one of these lines disables it /// </summary> /// <param name="diagnosticMonitorConfiguration"></param> void SetDiagnositcManagerScheduledTransferPeriods(DiagnosticMonitorConfiguration diagnosticMonitorConfiguration) { diagnosticMonitorConfiguration.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(5); diagnosticMonitorConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(5); diagnosticMonitorConfiguration.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(5); diagnosticMonitorConfiguration.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(5); diagnosticMonitorConfiguration.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(5); } /// <summary> /// Will add a full crashdump. /// Note: Full crashdumps are not available in asp.net roles /// </summary> void AddFullCrashDumps() { CrashDumps.EnableCollection(true); } /// <summary> /// Enables performance counters /// Note: PerformanceCounterConfiguration.CounterSpecifier is language specific and depends on your OS language. /// Note: For a complete list of possible PerformanceCounterConfiguration.CounterSpecifier values run "typeperf.exe /Q" /// </summary> /// <param name="diagnosticMonitorConfiguration"></param> void AddPerformanceCounterMonitoring(DiagnosticMonitorConfiguration diagnosticMonitorConfiguration) { var performanceCounterConfiguration = new PerformanceCounterConfiguration { CounterSpecifier = @"\Processor(*)\% Processor Time", SampleRate = TimeSpan.FromSeconds(15) }; diagnosticMonitorConfiguration.PerformanceCounters.DataSources.Add(performanceCounterConfiguration); } /// <summary> /// By default all Windows events to the Application and System logs are stored in the Azure table storage /// Note: Decide here what Windows event logs you are interested in seeing, you can also filter out events /// </summary> /// <param name="diagnosticMonitorConfiguration"></param> void AddEventLoggingFromWindowsEventLog(DiagnosticMonitorConfiguration diagnosticMonitorConfiguration) { // Syntax: <channel>!XPath Query // See: http://msdn.microsoft.com/en-us/library/dd996910(VS.85).aspx diagnosticMonitorConfiguration.WindowsEventLog.DataSources.Add("Application!*"); diagnosticMonitorConfiguration.WindowsEventLog.DataSources.Add("System!*"); } void StartDiagnosticManager(DiagnosticMonitorConfiguration diagnosticMonitorConfiguration) { DiagnosticMonitor.Start("DiagnosticsConnectionString", diagnosticMonitorConfiguration); } public void EnableAzureDiagnostics() { var diagnosticMonitorConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration(); SetDiagnositcManagerScheduledTransferPeriods(diagnosticMonitorConfiguration); AddFullCrashDumps(); AddPerformanceCounterMonitoring(diagnosticMonitorConfiguration); AddEventLoggingFromWindowsEventLog(diagnosticMonitorConfiguration); StartDiagnosticManager(diagnosticMonitorConfiguration); } } } 

Config:

  <system.diagnostics> <trace> <listeners> <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics"> </add> </listeners> </trace> </system.diagnostics> 
+5
source

Further changes have been made to Azure Log ....

Recording through Trace.TraceXXXX (for example, Trace.TraceInformation) will now be registered in the Windows Azure file system (~ \ LogFiles \ Application * .txt).

To view these files, you need to access the ftp website (enable through the Azure Management Portal / Dashboard / Deployment Credentials).

First you need to activate logging on the website settings page, which you can access either from Visual Studio (Server Explorer / Windows Azure Web Sites / Site Name / View Settings) or from the Azure management portal (in the "Settings / Application" section "Diagnostics / Registration of applications).

These logs can also be seen from the Azure Live Web site from the Visual Studio output window (make sure you select "Windows Azure Logs - xxx" from the "Show Output" drop-down list) if you right-click on the web site in Visual Studio Server Explorer (under Windows Azure websites) and select "View Streaming Logs in the Output Window".

Entrance to the Visual Studio output window is included in Scott Gug’s blog ( http://weblogs.asp.net/scottgu/archive/2013/04/30/announcing-the-release-of-windows-azure-sdk-2-0- for-net.aspx )

NB: I just tried this in VS2012. Not sure if it also works in VS2010.

+4
source

Source: https://habr.com/ru/post/1382158/


All Articles