Design a site like this with
Get started

The Benefits of Logging Your Code

As a junior developer, I am constantly looking to implement coding best practices in my routine and pass along what I’ve found to the development team that I’m in. Logging was one of them.

I noticed that no one was using any logging other than console output. While that is fine while developing the Web App, it’s not practical in a production environment. The last thing you want to do is ask the client to open up developer mode on the browser to get some data written to the console. Believe me, that is a bad idea.

You can use a slew of tools to add logging to your code. For me, I chose NLog as my tool of choice, dumping all of the data onto our Splunk account. I also set up Splunk to alert me if NLog recorded any error events. These alerts give me a heads up before the client contacts me about an issue.

Those error alerts already have come in handy. I received one from one of my web apps and with the alert information, I was able to create a support ticket on behalf of the web app owner, putting it in my queue.

When I had the time to work on the issue, I am able to duplicate it in the test environment and gather additional log information to narrow down the root cause. You don’t know how much of a time saver it is to not only log the error traps but certain data such as variables and objects. It gives a complete picture of what is going on and what you need to do to fix the bug.

Another thing that I did was to create a template for NLog for others in my team to use. All they have to do is fill in their name, email, and application name. All of that along with the error is used in Splunk to send out the email alerts to the team leader and to the developer of the application. The boss likes it because it keeps him in the loop.

I’m sure there are newer ways of analyzing errors in real-time with application insights but that is down the road. Right now, what we have is working. What logging system are you using? Do you like it? Let me know in the comments.