Logging from an azure console app as a web job - azure

I am in search for a good way to log various messages while being able to use functions, logic, monitoring, etc to get notified or run a certain task to fix a problem and notify someone.
What I have in mind is something like "If a specific error happens send me a notification or restart a service"
What I currently already have is an app service that holds 10 web jobs(continuous, triggered). Two of them use the Azure Web job SDK and the rest of them are plain .net core console apps. All of them generate structured logs using serilog and are saved to blob storage.
Is there something I am missing? I don't want to reinvent the wheel here.

You can use application insights with webjobs, more details are here.
You can also set an alert in application insights if error occurs, refer to this doc.
Any more questions please let me know.

Related

Azure Linux App Service Not Displaying Application Logs

I've set up a linux based azure app service and am unable to see log messages from the application itself in both the "log stream" and "logs" tab of the monitoring options. It is important to note I can see start up messages in the logs for the deployed application and can see outputs when get and post requests are made to the corresponding connection url so i know its running (Also the tasks the application is written to perform are carried out). Additionally, in the "App Service Logs" tab I have "Application Logging" set to "File System" as is standard for what I'm trying to output but this hasn't resulted in any in-application logs being visible.
Lastly about a year ago I managed to set up two other linux based azure app services that work completely as desired and output the in app log messages to the stream and cannot replicate this behaviour with this one. I feel there is just some setting or property somewhere i have overlooked but no matter how many different setting tabs I investigate I cannot spot any significant differences.
Are there any somewhat hidden options or requirements to be aware of in order to get in-application logs to be outputted to a linux based app services "log stream"? Or some other solution at a higher level in the azure resource group, workspace, application insights etc that may solve this issue? Any help and suggestions are greatly appreciated thank you.
I have tested in my environment.
Go to Your App Service --> Select Diagnose and Solve Problems --> Click on Availability and Performance --> Select Application Logs
You should be able to see the Application Logs, Platform Logs and Deployment Logs here.
Log Stream gives you the live logs of your application. The logs displayed in the Application logs should be seen in the Log Stream.

Monitoring Azure WebJob & Function App Failures

I'm currently acting as the SharePoint admin for a company that has some code jobs (mix of WebJobs and Function Apps) running in the background of an O365 site, performing some misc tasks like ensuring the webhook sub is still active, cloning sites, and populating clones with info from a form in SharePoint.
These jobs are mission critical as they are linked to a crisis management site so I've been asked to put in some monitoring for assurance that we'll be alerted if any fail, either as part of a schedule or on-demand (again there is a mix of these).
The problem is I don't really understand much of Azure, other than it replaces the farm solutions in SP as a place to run back-end code, especially with the plethora of names for things that seem to me to be pretty similar.
Can anyone reccomend an easy way I can set up some sort of monitoring trigger for the individual webjobs and functions for a failure, ideally just using the built in Azure control panel (i.e. without having to deploy any code - I'm really not a C# and the like coder).
For both Function and webjob, you all could use Application Insight to monitor them.
For Function, Ivan has linked the official doc: Monitor Function, and for webjob official doc actually has a tutorial about configuring Application Insight:Add Application Insights logging.
Also you could refer to my answer about using application insight. Use this package:Microsoft.Azure.WebJobs.Logging.ApplicationInsights and add JobHostConfiguration.
string instrumentationKey = Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY");
if (!string.IsNullOrEmpty(instrumentationKey))
{
// build up a LoggerFactory with ApplicationInsights and a Console Logger
config.LoggerFactory = new LoggerFactory().AddApplicationInsights(instrumentationKey, null).AddConsole();
config.Tracing.ConsoleLevel = TraceLevel.Off;
}
Then you will be able to add webjob logs. Hope this could help you.

Persistent application logs for NodeJS app on azure app service

I have a nodejs app which is nothing but a BOT built using Microsoft's bot builder framework. I created an azure app service to host this app. I would like to find a way to persist all the application logs and web server logs as well (if possible) to some persistent store. Just like native web applications where we can look up logs on a app server & debug the application issues.
After doing some research I found official document from microsoft on this but looks like it has following limitations.
We can't use file storage option of app service as it's good for 12
hours only so logs will not be saved forever.
Currently only .NET application logs can be written to the blob
storage. Java, PHP, Node.js, Python application logs can only be
stored on the file system (without code modifications to write logs
to external storage).
I would like to check if anyone has tried any different approach for nodejs app. If yes then please share.
Thank you.
So I would respond by saying that this is not really a Bot specific problem... meaning you would have the same problem if you were writing a vanilla Web API and wanted to have persistent logs. You need to pick on a logging technology that let's you log to a more persistent store than just the file system.
Since you're using Node you might want to look at leveraging the Winston logging framework which has an abstraction for various transports to be plugged in. Then you would plug in the Azure Storage Blob Transport when running in production and that will ensure that your logs are written out to Azure Storage.
Still, you'd have to go collect those from Azure Storage and aggregate them yourself which can be painful. If you really want real-time a distributed tracing system though, you might want to look into using Application Insights instead. There's even a Winston transport for that as well if you want to stay abstracted from using AI directly and just use it as another log stream.

Logging a Node.js-Azure app, using Bot Framework

I have a Node application (Bot Framework bot) hosted on Azure. What's the best way to log information for debugging? For example, as far as i'm aware, using console.log() isn't helpful because there is no console to look at in Azure. I also do not want to call tons of session.send() to the client.
So whats the best way to get some sort of debug logging?
You can leverage the Diagnostic Log extension on Azure Web Apps. Login your web app in Azure portal(https://ms.portal.azure.com/). Click on Diagnostic logs in settings option and Turn On Application logging in Diagnostic Logs Tab.
And then you can login the Kudu console site of your web app(https://<Your_Webapp_name>.scm.azurewebsites.net/DebugConsole) and browse to your Application folder(D:\home\LogFiles\Application folder).
Otherwise, you can click the Diagnostic dump on the top nav bar of the kudu console site to download the log files.
On the other hand, you can use the Log stream tool on the Azure portal(https://ms.portal.azure.com/) for a real time debugging online.
At last, you can integrate a 3rd part node.js log modules, such like winston into your application. And catch the logs into your own log file.
Any further concern, please feel free to let me know.
This guide seems to answer your question: https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-debug. (If not, please provide additional info about what you'd like to achieve.)

AzureWebApp: Monitor Application Logs

I'm building an Azure web-app and if there are certain unexpected errors, I want to be able to bubble it up in the Azure Dashboard / add alerts.
Any System.Diagnostics.Trace.TraceError() messages are logged to the ApplicationLog. Is there a way to add alert/monitoring-graphs for these in Azure Portal?
I think and most flexible option for configuring alerts on Web Apps is enabling the Application insights have the App Insight be one of your event sources:
https://azure.microsoft.com/en-us/documentation/articles/app-insights-search-diagnostic-logs/
Once you have the Application Insight setup then you can easily set any kind of alerts based on the diagnostics that are collected:
https://azure.microsoft.com/en-gb/documentation/articles/app-insights-alerts/
Aram's links below really helps. Please read them.
To Get this working:
Add the ApplicationInsights to your project.
(Optional) If you want log traces (System.Diagnostics.Trace) to be searchable on insights, add Microsoft.ApplicationInsights.TraceListener nuget to your project.
Use telemetryClient.TrackException() to place a server exception
when you hit a critical error.
Add an alert on Azure portal to check for ServerExceptions within the given time window.

Resources