{"id":9491,"date":"2015-05-14T15:21:00","date_gmt":"2015-05-14T15:21:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2015\/05\/14\/collect-data-from-a-windows-service-using-the-intellitrace-standalone-collector\/"},"modified":"2022-08-01T01:15:18","modified_gmt":"2022-08-01T09:15:18","slug":"collect-data-from-a-windows-service-using-the-intellitrace-standalone-collector","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/collect-data-from-a-windows-service-using-the-intellitrace-standalone-collector\/","title":{"rendered":"Collect data from a windows service using the IntelliTrace Standalone Collector"},"content":{"rendered":"<p>In this blog post I am going to walk you through how to collect data from a windows service using the <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2014\/08\/07\/intellitrace-standalone-collector-is-back.aspx\">IntelliTrace Standalone Collector<\/a>. For the purpose of this post I will be using a windows service I created called \u201cMyWindowsService\u201d.<\/p>\n<blockquote>\n<p><strong>Note:<\/strong> If you already have Visual Studio installed on the machine the windows service is running you don\u2019t necessarily need to follow this guide because <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2015\/05\/14\/intellitrace-in-visual-studio-enterprise-2015-now-supports-attach.aspx\">IntelliTrace now supports attach<\/a>! Simply <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/3s68z0b3.aspx#BKMK_Attach_to_a_running_process\">attach to the running windows service using Visual Studio<\/a> and IntelliTrace will start collecting data and showing it in the Diagnostic Tools window just like it does when you debug using F5. The only caveat is that you cannot collect calls information when you are attaching, you can only collect events. If you want to collect calls information you\u2019ll need to follow this guide instead.<\/p>\n<\/blockquote>\n<h2>Step 1 \u2013 Download the IntelliTrace Standalone Collector<\/h2>\n<p><a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=44909\">Download the latest version of the IntelliTrace Standalone Collector<\/a>. Don\u2019t worry about the version of Visual Studio you have, it\u2019s backwards compatible. What you get is a self-extracting .exe file and if you run it you will get an IntelliTraceCollection.cab file copied to a folder of your choice. I chose the folder C:IntelliTrace.\u00a0<\/p>\n<h2>Step 2 \u2013 Extract the .cab file<\/h2>\n<p>Use the following command to expand the .cab file (yes, the dot at the end is necessary):<br \/>\n**expand \/f:* IntelliTraceCollection.cab . **<\/p>\n<p>I used the above command to extract everything into the directory C:IntelliTrace.\u00a0<\/p>\n<h2>Step 3 \u2013 Configure your collection plan XML file<\/h2>\n<p>The collection plan is the compilation of all settings that tell IntelliTrace what data to collect while the windows service is running:<\/p>\n<ol>\n<li>What interesting events to collect<\/li>\n<li>Whether to collect method calls and parameters<\/li>\n<li>Whether to whitelist or blacklist certain assemblies<\/li>\n<\/ol>\n<p>The .cab file contains two collection plans out of the box:<\/p>\n<ul>\n<li><strong>collection_plan.ASP.NET.trace.xml:<\/strong> Equates to the default IntelliTrace setting in Visual Studio, which means it will collect only events (not method calls) and not the complete list.<\/li>\n<li><strong>collection_plan.ASP.NET.default.xml:<\/strong> Equates to selecting \u201cIntelliTrace events and call information\u201d from the General tab of the IntelliTrace options in Visual Studio.<\/li>\n<\/ul>\n<p>Pick whichever of the two files sounds like a good starting point and make whatever changes you need. I recommend starting with the first one since collecting both events and call information adds considerable overhead. You can make the changes <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2015\/03\/09\/editing-the-intellitrace-collection-plan.aspx\">either using a community tool or by editing the XML file manually<\/a>.\u00a0<\/p>\n<h2>Step 4 \u2013 Specify the directory you want IntelliTrace to save its data in<\/h2>\n<p>You need to make one final edit to your collection plan that unfortunately has to be done manually by editing the XML file:<\/p>\n<ol>\n<li>Open the XML file in your editor of choice<\/li>\n<li>Find the XML element \u201cLogFileDirectory\u201d<\/li>\n<li>Give it a value, for example: <LogFileDirectory>C:Logs<\/LogFileDirectory><\/li>\n<\/ol>\n<p>That\u2019s the path to the directory in which IntelliTrace will save as an .itrace file all of the data it collects. You must make sure that the user the windows service is running as has read and write access to this directory.\u00a0<\/p>\n<h2>Step 5 \u2013 Register your Windows Service and make sure it starts<\/h2>\n<p>Register your Windows service on the target machine so that it shows up on the list of services available and make sure it can be started successfully:<\/p>\n<p><img decoding=\"async\" style=\"float: none;padding-top: 0px;padding-left: 0px;margin-left: auto;padding-right: 0px;margin-right: auto;border-width: 0px\" title=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/05\/5635.clip_image002_thumb_0B0E8C8B.png\" alt=\"clip_image002\" width=\"544\" height=\"351\" border=\"0\" \/>\u00a0<\/p>\n<h2>Step 6 \u2013 Edit the registry<\/h2>\n<p>Using RegEdit navigate to the key HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesMyWindowsService and create a new Multi-String Value called \u201cEnvironment\u201d<\/p>\n<p><img decoding=\"async\" style=\"float: none;padding-top: 0px;padding-left: 0px;margin-left: auto;padding-right: 0px;margin-right: auto;border-width: 0px\" title=\"clip_image003\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/05\/6724.clip_image003_thumb_5FC9F583.png\" alt=\"clip_image003\" width=\"563\" height=\"311\" border=\"0\" \/><\/p>\n<p>Double click on it and set its value to be the following:<\/p>\n<blockquote>\n<p>COR_ENABLE_PROFILING=1<br \/>\n  COR_PROFILER={AAAAAA70-DFED-4CB4-A1D6-920F51E9674A}<br \/>\n  COR_PROFILER_PATH=<Path_where_collector_was_extracted>Microsoft.IntelliTrace.Profiler.14.0.0.SC.dll<br \/>\n  VSLOGGER_CPLAN=<Full_path_to_collection_plan_XML_file><\/p>\n<\/blockquote>\n<p><strong>Note:<\/strong> If you are trying to collect from a 64bit service, the COR_PROFILER_PATH must point to the 64bit version of the dll, which is in the subdirectory &#8220;x64&#8221;. For example: &#8220;C:IntelliTracex64Microsoft.IntelliTrace.Profiler.14.0.0.SC.dll&#8221;<\/p>\n<p>You must make sure that the user the windows service is running under has read and write access to both the directory the collector\u2019s DLL is in, as well as the directory containing the collection plan XML file. As you can see in the screenshot above I used the directory C:IntelliTrace for both. Also make sure the name of your collection plan XML file is correct, I used \u201cCollectionPlan.xml\u201d.<\/p>\n<h2>Step 7 \u2013 Restart your windows service<\/h2>\n<p>You are all set. As soon as you restart your windows service IntelliTrace will automatically start collecting data from it. As soon as you stop your service you will find one or more .itrace files in the log directory you specified during the previous step (I used C:Logs). You can now open the .itrace file using <strong>File > Open > File&#8230;<\/strong>\u00a0in Visual Studio to see what IntelliTrace has collected.<\/p>\n<h2>Wrapping up<\/h2>\n<p>We are always looking for feedback and comments for our features. You can leave general comments &amp; questions at the end of this blog post or via <a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/content\/content.aspx?ContentID=31113\">Send-a-Smile<\/a>, and submit feature requests to our <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\/category\/91797-intellitrace\">IntelliTrace UserVoice<\/a>. You can also <a href=\"https:\/\/twitter.com\/IntelliTrace\">send us a tweet<\/a> or visit the <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/vstudio\/en-US\/home?forum=vsdebug\">MSDN Diagnostics forums<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post I am going to walk you through how to collect data from a windows service using the IntelliTrace Standalone Collector. For the purpose of this post I will be using a windows service I created called \u201cMyWindowsService\u201d. Note: If you already have Visual Studio installed on the machine the windows service [&hellip;]<\/p>\n","protected":false},"author":127,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,225],"tags":[],"class_list":["post-9491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-git"],"acf":[],"blog_post_summary":"<p>In this blog post I am going to walk you through how to collect data from a windows service using the IntelliTrace Standalone Collector. For the purpose of this post I will be using a windows service I created called \u201cMyWindowsService\u201d. Note: If you already have Visual Studio installed on the machine the windows service [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/9491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/127"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=9491"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/9491\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=9491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=9491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=9491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}