How To Log From Azure Virtual Machines
How To Log From Azure Virtual Machines
One of the most common stacks deployed in Azure is .Net applications running in Windows Sever virtual machines, so you'll want to capture logs from two layers.
Join the DZone community and get the full member experience.Join For Free
Planning to extract out a few microservices from your monolith? Read this free guide to learn the best practice before you get started.
You have evaluated the many IaaS providers out there and you have decided on Azure Compute. Great choice! Azure is an ideal provider with broad support for various operating systems, programming languages, frameworks, tools, databases and devices. Azure also has the unique ability to facilitate hybrid deployments between the cloud and your Windows data centers.
As you begin developing and deploying in Azure your need for effective logging has no doubt grown. A tool like Logentries can make capturing, searching, analyzing and alerting on this log data very simple. Logentries, like Azure, has broad support for operating systems, programming languages, and other common tools. If you decide to deploy Ubuntu virtual machines be sure to check out the open source Linux Agent. Or perhaps you have deployed docker containers or a Node.js app.
One of the most common stacks deployed in Azure is .Net applications running in Windows Sever virtual machines. In this stack you will want to capture logs from two layers: the Windows Sever OS and the .Net application.
Capturing Logs From a Windows Server
The Windows Servers running in Azure Virtual Machines will be producing valuable data in the form of logs. Monitoring both the Windows Event Viewer and the logs created by IIS (Internet Information Services) will allow you to get insight into in the infrastructure of your application.
The Logentries Windows Agent takes only a couple minutes to install and can easily capture all of the pertinent data from your virtual machines. The Windows Agent can be downloaded from here.
After installation, the Windows Agent will automatically follow the Windows Event Viewer. You can follow your IIS logs by issuing an AgentService.exe follow command, like the one below:
This command will always follow the newest version of a file starting with
u_ex in the folder for IIS site 1.
Best Practice: Use NXLog to Send JSON Data
The Logentries Windows Agent effectively follows your Event Viewer and IIS logs out of the box. However, many DevOps professionals choose to send the data from these two sources as JSON for the added readability and ease of search.
Install and configure NXLog:
- Download NXLog from here.
- Once installed. Replace
C:\Program Files (x86)\nxlog\conf\nxlog.confwith the contents of our pre-made config, here.
- Change lines 76 and 87 to reflect a proper place to output your JSON logs.
- Start the NXLog service.
Configure the Windows Agent to follow the JSON logs:
Once you have NXLog producing JSON data, execute the following two AgentService.exe follow commands. Be sure to replace the paths below with the ones you entered for line 76 and 87 in your nxlog.conf.
AgentService.exe follow c:\test\eventlog.txt
AgentService.exe follow c:\test\iis1.txt
Unfollow the non-JSON event viewer and IIS logs.
Add the IIS Web Server Monitoring Pack (JSON Log File Format) community pack to your account to leverage the new JSON data.
Logging From a .NET Application
Now that you are successfully capturing the data from the Windows Sever OS let’s turn our attention to the .Net application in your stack.
This post will review setting up the Logentries Log4Net appender. Review the full documentation here, abbreviated steps below:
- Log into your Logentries account or Create a free Account.
- Create a new ‘Manual’ log and generate a new log token, by clicking the “+ Add New” button in the top left corner of the Logentries application, and then “Add a Log”. Keep your new token for step 4.
- Install the
logentries.log4netNuget package plug library to your application.
- Add the appropriate
<appender>block containing your token to your Log4Net configuration as detailed in the documentation.
- View your logs in Logentries.
Best Practice: Alert From Log4Net Using Logentries
Configuring alerts to be sent from your .Net applications via Logentries is a great way to stay on top of issues with your application and service.
You may want to setup a simple Basic alert that notifies you every time your .Net app throws a FATAL error. For example:
Published at DZone with permission of Justin Buchanan , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.