Using SEQ in Azure without AKS and without using a dedicated VM
So you want to log events and have a pretty dashboard out of the box? SEQ for the rescue!
If you don´t know “DataLust Seq” solution, please start by the official website, in https://datalust.co/ and consider subscribing to their plans, It’s a really great service to manage logs in .net solutions, and best of all has some amazing UI!
But this brings me to the motive I´m writing this! I wanted to use SEQ amazing capacities but I did not want to create an AKS cluster just for it or deploy a Virtual Machine! I wanted it to be used like in a web app! That would be great!
And just for you, YES IT’S POSSIBLE!!! =) And you can have a super centralized logging solution to maintain your apps under control!
So, this document will try to explain how to make it possible to have SEQ as a web app on Azure but also help you out on making a couple of ARM templates so you can deploy them via Azure DevOps.
Using Azure Portal
So, we can have access to the public docker image of SEQ and we can deploy it to a web app, and with a couple of tweaks, we have it up and running.
Create a web app
So let's create a web app, and when doing so, use the following settings:
- Publish as a docker container
- Operating System Linux
Click next, and now let’s point out where is the docker image that we need to make our solution work, so on the Docker screen, select Docker Hub as the Image source, and in the image and tag select datalust/seq:latest
Now, you can go and fill in whatever you think it’s needed and create the web app!
After the web app created we have to give two additional settings, so the web app can start successfully, as the docker container requires that we accept the terms and conditions, and also we have to set a port, so go to the web app in the Azure Portal and add the following two settings and don’t forget to SAVE.
ACCEPT_EULA
=>Y
WEBSITES_PORT
=>80:5341
So, you added the app settings and saved them, now we have to make this applied to the web app, so, please, restart the web app, so the container can detect those new app settings!
And that’s it, you can now go to the URL of your web app and you´ll have an amazing dashboard!
Well, but we need to save the logs persistently, or else, we could not use this in a good manner, and now, we are saving them inside the container… NOT COOL!
What about saving them in a Storage account? YEAH!
So, if you don´t have a storage account in Azure, the day has come that you should create one ( its a very simple thing, just add a resource of type Storage Account =) ) but you can use one that you have already, it’s not mandatory to create a new one
So go to the web app in the Azure Portal and navigate to Configuration, then inside choose the tab “PATH MAPPINGS” and add a New Azure Storage Mount, a new blade will appear where you will give a name to this mount, select the storage account and the container and the mount path should be /data. Also, please make sure you have configuration options set to Advanced and the Storage Type set to Azure Files. If you plan to use an arm template, you also need to track the access key that is auto-filled by Azure, to insert in the ARM. When you create the storage account (or use the one that you already have), in the Storage Account resource, go to File Shares and create one, and give it the name that you will insert in the Share Name when binding in the web app.
It’s done! Your SEQ server now stores the logs in the Storage Account and we are good to go!!!
Feeding Data
To feed data to the SEQ server, please check the Datalust documentation on it in https://datalust.co/ ! I use Serilog sink in my solutions… will give you a snippet.
So normally I add the Serilog nugget to the solution and also the Serilog.Sink.Seq nugget and then in the Program.cs
Nuggets (I´m using a .net5.0 solution):
<PackageReference Include=”Serilog.AspNetCore” Version=”4.1.0" />
<PackageReference Include=”Serilog.Sinks.Seq” Version=”5.0.1" />
In my appsettings.json file, I also have an entry to Serilog.SeqServerUrl that points to my newly created azure web app with the SEQ server!
Now we have to call this method, I normally call it right in the Main method of Program.cs, something like this:
What misses? Having Serilog set as the prefered logging system for our app, and we do that on inside that method that shows on my last screenshot, the BuildWebHost().
And that’s it! Now we are feeding our SEQ server! Please note that this was a very rudimentary tutorial, you can and should improve your logs, explore the Serilog solution and provide the best data possible to SEQ and also explore the SEQ server!
BONUS ROUND: Let's bring this to Azure DevOps
So, and how about we automatically have this so, let’s imagine, we want to have it ready to be deployed from DevOps for multiple solutions, I suggest that you use the tool to have it generate the ARM template, so go to the created web app, find Automation part, and select Export Template. It will generate the template for you, you might want to have the server farm as a parameter so you can change the server when you want!
Also, note that to use the Storage Account to persist the logs, the created ARM probably does not have the access key configured ( its the key for the Storage Account, you can always find it in the Storage Account in the portal and looking for the Access keys, then select either Key1 or Key2 (not the Connection string, we just want the key ) and we have to add it to the ARM in
azureStorageAccounts.<NAME-OF-THE-SHARE> and add the “accessKey” property…
Something like this:
Of course, the key is only required if you set up your security, there are also other ways to protect the access to the Azure Files that SEQ will create and use.
Thanks for reading! Hope you enjoyed it!