Retrace will reach End of Life on March 31, 2027. Click here to learn more.

Debugging Windows Services with Prefix

By: mwatson
  |  December 7, 2016
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 is now included in Prefix.

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-enablestackify

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.

Also Read-https://stackify.com/humanitarian-toolbox-lets-save-lives-keyboard/

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 performance, 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-list

Captured trace showing a debug statement and an HTTP call

timer-download-page

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.

Also read- https://stackify.com/retrace-prefix-product-updates-august-2022/

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-detail

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-list

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

queue-detail

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.

Get Prefix Power on a server!
Get Prefix Power on a server!

Improve Your Code with Retrace APM

Stackify's APM tools are used by thousands of .NET, Java, PHP, Node.js, Python, & Ruby developers all over the world.
Explore Retrace's product features to learn more.

Learn More
togel slot situs toto pucuk4d agb99 togel toto slot toto togel toto slot indobet situs toto toto slot toto slot toto slot toto toto situs toto toto slot slot depo 10k toto togel 8kuda4d toto judi bola kenangan4d toto situs toto toto toto toto situs toto toto toto slot bobatoto daftar situs toto logototo situs toto situs toto toto bydplay patentoto situs toto slot 4D situs toto leon188 situs toto slot gacor terbaru toto toto slot toto situs toto situs toto MORFINTOTO ilmutoto toto mix parlay bayitoto toto toto toto toto ilmutoto toto toto mawar800 login popotogel prize hongkong malam ini toto joker11 toto slot pucuk4d lingkartoto Pucuk4D Login UGSLOT slot gacor ilmutoto toto slot gacor rp888 https://foundvinylrecords.com/ depo 5k slot gacor toto slot gacor toto panen100 semibola slot gacor Pakde4D situs gacor MySlot188 toto togel 77ag monk4d popo togel tikus4d https://asupantoto.co/ Login Batak5D pompa4d lingkartoto Pakde4D lingkartoto emas 55 AMANAHTOTO efekjitu slot pascol4d login pascol4d login sbobet88 sbobet88 https://nolimithoki.dev/ ini777 benteng786 dinasti33 slot toto slot gacor kaskustoto situs toto slot88
togel slot situs toto pucuk4d agb99 togel toto slot toto togel toto slot indobet situs toto toto slot toto slot toto slot toto toto situs toto toto slot slot depo 10k toto togel 8kuda4d toto judi bola kenangan4d toto situs toto toto toto toto situs toto toto toto slot bobatoto daftar situs toto logototo situs toto situs toto toto bydplay patentoto situs toto slot 4D situs toto leon188 situs toto slot gacor terbaru toto toto slot toto situs toto situs toto MORFINTOTO ilmutoto toto mix parlay bayitoto toto toto toto toto ilmutoto toto toto mawar800 login popotogel prize hongkong malam ini toto joker11 toto slot pucuk4d lingkartoto Pucuk4D Login UGSLOT slot gacor ilmutoto toto slot gacor rp888 https://foundvinylrecords.com/ depo 5k slot gacor toto slot gacor toto panen100 semibola slot gacor Pakde4D situs gacor MySlot188 toto togel 77ag monk4d popo togel tikus4d https://asupantoto.co/ Login Batak5D pompa4d lingkartoto Pakde4D lingkartoto emas 55 AMANAHTOTO efekjitu slot pascol4d login pascol4d login sbobet88 sbobet88 https://nolimithoki.dev/ ini777 benteng786 dinasti33 slot toto slot gacor kaskustoto situs toto slot88