6

My website, written in ASP.NET and i used EventLog to write logs into the event viewer. It is already been running in the production (OS: Windows Server 2012 R2) and no problems encountered upon logging some errors. I am now planning to migrate the server to Azure - App Services. I wonder if my code in logging the errors would still work after moving to Azure - App Services?? If yes then how do i view the error that have been logged by my website?? I cannot see Event Viewer in the Azure - App Services. If no then what is the simplest and fastest alternate way to replace my code in logging the errors??

Here is my code:

public static void LogEventLog(string message, EventLogEntryType logType)
    {
        string source = AppConfig.ErrorEventViewerSource;

        // Since we can't prevent the app from terminating, log this to the event log. 
        CreateEventSource(source);

        // Create an EventLog instance and assign its source.
        EventLog myLog = new EventLog();
        myLog.Source = source;
        myLog.WriteEntry(message, logType);

    }



    public static void CreateEventSource(string source)
    {
        if (!EventLog.SourceExists(source))
        {
            EventLog.CreateEventSource(source, "Application");
        }
    }
heyou
  • 315
  • 1
  • 7
  • 14
  • I am also new to Azure but as per my understanding you need to push event logs to diagnostics store. Refer this link - https://azure.microsoft.com/en-in/documentation/articles/web-sites-enable-diagnostic-log/#how-to-view-logs-in-application-insights – Sanket Jul 04 '16 at 04:16

2 Answers2

2

I think the correct solution is to connect your app to application insights using one of the methods described here. For the short term, to get mine working I had to remove the call to CreateEventSource() and write to an existing log since my app doesn't have permission to create a new log on the app service host.

sirdank
  • 3,351
  • 3
  • 25
  • 58
  • Agree i already switch to application insights. I now log exception error directly to the application insights. Thanks! – heyou May 22 '18 at 01:22
1

I know this is an old topic, but this may help someone searching around as I was...

You can use the Microsoft.Extensions.Logging.ILogger object to log out. Then in Azure, if you go to your App Service, left-hand menu, "Diagnose and solve problems" --> Diagnostic Tools (in the main pane) --> Support Tools/Application Event Logs on the left-hand menu of the new screen.

You should see your events output in that log stream!

I should note that this won't be the complete detailed log, but will be the Errors. For the complete logging solution, connect your app to Application Insights as previously suggested. However, for a quick and easy solution, to see error output, this is quite handy.