Welcome!

Performance. Errors. Logs. One Tool. Everything Developers Need to Support Their Apps

Stackify Blog

Subscribe to Stackify Blog: eMailAlertsEmail Alerts
Get Stackify Blog via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Blog Feed Post

Debugging Windows Services with Prefix

Prefix enables developers to easily see what their code is doing as they write and test their code, including SQL queries, HTTP calls, errors, logs, and much more. Prefix is most often used with web applications, but .NET Windows Services are also supported. This article discusses how to use Prefix with a Windows Service or console application.

Learn more about Prefix

Getting Started

First thing you need to do is install Prefix. Support for non web applications also requires Prefix Premium. So you need to start a trial of Premium or buy a license.

By default Prefix only profiles web applications. So you need to tell Prefix to profile your application when it starts. There are a couple ways to do this including a command line switch of “/EnableStackify” or by creating a small ProfileProcess.txt file.

For Prefix, I suggest the command line arguments way since you are most likely running your app from Visual Studio. In the project properties add the command line argument and you should be good to go!

vs-enablestackifyhttp://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 300w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 768w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 1024w" sizes="(max-width: 1402px) 100vw, 1402px" />

Types of Windows Services/Console Apps

These types of apps can be used to do a wide variety of things. We will attempt to cover some of the most popular uses and how Prefix can be valuable for those. Depending on your type of application, different configuration steps will be required. We will walk through three common scenarios:

  • Timer based events
  • Job scheduler, like Quartz.net
  • Queue processing

We have a sample project on GitHub that shows how to do all of these.

Note: You can also enable Prefix for “self hosted web apps”. Review: Self hosted WCF or Self hosted Web API for more details on how to do this.

How it works – Tracking custom code operations

For non web applications, there is no real defined scope of what an “operation” is. Prefix and Retrace are designed to track short operations (< 60 seconds) that happen often. If you are trying to track a segment of code that never ends, it won’t work with Prefix. Tracking custom operations is done by using the ProfilerTracer object within StackifyLib. This creates a defined operation from start to finish that can be named and tracked as a single operation.

Example: Timer based events

It is common for service apps to do things on a scheduled interval like polling a database, file, website, etc. To make this show up in Prefix (or Retrace), all you need to do is define the scope of the operation.

Example code with operation defined:

How it looks in Prefix

List of the timer based transactions happening every few seconds

download-page-listhttp://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 300w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 768w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 1024w" sizes="(max-width: 467px) 100vw, 467px" />

Captured trace showing a debug statement and an HTTP call

timer-download-pagehttp://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 300w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 768w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 1024w" sizes="(max-width: 1410px) 100vw, 1410px" />

See sample project for a more complete demo: TimerExample

Example: Quartz.net Job Scheduler

If you have ever managed a bunch of Windows Scheduled Tasks, you know how much of a nightmare they are. Using an open source job scheduler like Quartz can eliminate those, while at the same time allowing you to run the jobs across multiple computers. In this example we will show you how to track Quartz jobs with Prefix (and Retrace).

We suggest making all of your jobs inherit from a base job class that you create. That makes it easy to have a single place in your code to track the scope of the jobs, do logging, or other management operations.

How it looks in Prefix

List of quartz operations occurring

quartz-list

Detail view of a quartz job that just does a HTTP call as a simple example

quartz-detailhttp://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 300w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 768w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 1024w" sizes="(max-width: 1538px) 100vw, 1538px" />

See sample project for a more complete demo: QuartzExample

Example: Processing queued messages

A common application design is using queues to increase application resilience, scalability, etc. Monitoring applications that handle queued messages can be a mystery. With Prefix (and Retrace) you can track each of these as a transaction to have visibility in to what is going on.

For this example we are showing how to track an Azure Service Bus message pump.

How it looks in Prefix

List of captured operations from processing queue messages

queue-listhttp://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 300w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 768w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 1024w" sizes="(max-width: 464px) 100vw, 464px" />

Example of detailed trace of processing the queued message. In this example we aren’t doing anything except a couple log statements.

queue-detailhttp://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 300w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 768w, http://1piygz303e2p3ze2nt2kfhla.wpengine.netdna-cdn.com/wp-content/uploa... 1024w" sizes="(max-width: 1549px) 100vw, 1549px" />

See sample project for a more complete demo: QueueProcessor

Other Scenarios

Windows services can be used for a very wide variety of purposes beyond the three scenarios described above. As long as you can define a scope of work that makes sense to be a repeatable operation, you should be able to make Prefix track the individual operations of your code.

Read the original blog entry...

More Stories By Stackify Blog

Stackify offers the only developers-friendly solution that fully integrates error and log management with application performance monitoring and management. Allowing you to easily isolate issues, identify what needs to be fixed quicker and focus your efforts – Support less, Code more. Stackify provides software developers, operations and support managers with an innovative cloud based solution that gives them DevOps insight and allows them to monitor, detect and resolve application issues before they affect the business to ensure a better end user experience. Start your free trial now stackify.com