Collect data from a windows service using the IntelliTrace Standalone Collector
May 14, 2015
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 “MyWindowsService”.
Note: If you already have Visual Studio installed on the machine the windows service is running you don’t necessarily need to follow this guide because IntelliTrace now supports attach! Simply attach to the running windows service using Visual Studio 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’ll need to follow this guide instead.
Step 1 – Download the IntelliTrace Standalone Collector
Download the latest version of the IntelliTrace Standalone Collector. Don’t worry about the version of Visual Studio you have, it’s 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.
Step 2 – Extract the .cab file
Use the following command to expand the .cab file (yes, the dot at the end is necessary):
expand /f:* IntelliTraceCollection.cab .
I used the above command to extract everything into the directory C:\IntelliTrace.
Step 3 – Configure your collection plan XML file
The collection plan is the compilation of all settings that tell IntelliTrace what data to collect while the windows service is running:
- What interesting events to collect
- Whether to collect method calls and parameters
- Whether to whitelist or blacklist certain assemblies
The .cab file contains two collection plans out of the box:
- collection_plan.ASP.NET.trace.xml: Equates to the default IntelliTrace setting in Visual Studio, which means it will collect only events (not method calls) and not the complete list.
- collection_plan.ASP.NET.default.xml: Equates to selecting “IntelliTrace events and call information” from the General tab of the IntelliTrace options in Visual Studio.
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 either using a community tool or by editing the XML file manually.
Step 4 – Specify the directory you want IntelliTrace to save its data in
You need to make one final edit to your collection plan that unfortunately has to be done manually by editing the XML file:
- Open the XML file in your editor of choice
- Find the XML element “LogFileDirectory”
- Give it a value, for example: <LogFileDirectory>C:\Logs</LogFileDirectory>
That’s 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.
Step 5 – Register your Windows Service and make sure it starts
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:
Step 6 – Edit the registry
Using RegEdit navigate to the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MyWindowsService and create a new Multi-String Value called “Environment”
Double click on it and set its value to be the following:
COR_ENABLE_PROFILING=1
COR_PROFILER={AAAAAA70-DFED-4CB4-A1D6-920F51E9674A}
COR_PROFILER_PATH=<Path_where_collector_was_extracted>\Microsoft.IntelliTrace.Profiler.14.0.0.SC.dll
VSLOGGER_CPLAN=<Full_path_to_collection_plan_XML_file>
Note: 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 “x64”. For example: “C:\IntelliTrace\x64\Microsoft.IntelliTrace.Profiler.14.0.0.SC.dll”
You must make sure that the user the windows service is running under has read and write access to both the directory the collector’s 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 “CollectionPlan.xml”.
Step 7 – Restart your windows service
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 File > Open > File… in Visual Studio to see what IntelliTrace has collected.
Wrapping up
We are always looking for feedback and comments for our features. You can leave general comments & questions at the end of this blog post or via Send-a-Smile, and submit feature requests to our IntelliTrace UserVoice. You can also send us a tweet or visit the MSDN Diagnostics forums.
EWWWWWWWWWWWWWWWW REGISTRY !!!! EWWWWWWWWWWWWWWWWWWWWWWWWW11111111111111
I get it, having to edit the registry is not fun.
I am seeing this in event log
.NET Runtime version 4.0.30319.0 – The profiler has requested that the CLR instance not load the profiler into this process. Profiler CLSID: '{2AA1AA98-2CAA-4FCF-86CE-EFA007737E83}'. Process ID (decimal): 10048. Message ID: [0x2516].
Here is my Env Registry entry
COR_ENABLE_PROFILING=1
COR_PROFILER={2AA1AA98-2CAA-4FCF-86CE-EFA007737E83}
COR_PROFILER_PATH =C:IntelliTraceCollectorMicrosoft.IntelliTrace.Profiler.12.0.0.SC.dll
VSLOGGERCPLAN=C:IntelliTraceCollectorcollection_plan.ASP.NET.debug.xml
@Jose:
1. Please make sure that the user the service is running under has read and write access to C:IntelliTraceCollector as well as the directory you specified for the .itrace log files when you manually edited the collection plan. If in doubt, temporarily give permissions to "Everyone".
2. If you didn't download the collector from the link in this blog, please try downloading it again.
3. Any other events in the event log related to this? Anything that happened around the same time basically.
Hi Angelos,
I got same behavior as Jose.
I did all things you suggested.
Do i have to have installed VS 2013?
Thanks,
Maciej
I got it.
There cannot be any additional char in xml tag <LogFileDirectory>.
It must be exactly like it is in article: <LogFileDirectory>C:Logs</LogFileDirectory>, otherwise it failes.
Regards,
Maciej
Of courseit can be any log folder path.
I click on 'Send-a-Smile' above and I get a page saying 'This content has been removed'!
@[[Matt]] I have updated the Send-a-Smile link
@Angelos. Thanks. NB I think the 'Send a screenshot' checkbox should be unchecked by default. I had a fat finger moment and accidentally submitted prematurely – containing a screen shot that I ought not have. It should 'fail safe'. (Even though it was my fail)
Where can I get the CLSID of the VS2015 standalone profiler (x64)?
It looks as {2AA1AA… is invalid, at least I get such entry in the application event log:
".NET Runtime version 4.0.30319.17929 – Loading profiler failed. COR_PROFILER is set to an invalid CLSID: '{2AA1AA98-2CAA-4FCF-86CE-EFA007737E83} '. HRESULT: 0x80070057. Process ID (decimal): 5096. Message ID: [0x2502]."
I am also running into an issue that the CLSID is invalid. I have tried this one in this article and numerous others from other articles (most/all dated earlier than this one).
Any assistance would be greatly appreciated.
@Sebastian, @DMartin I'm guessing that you are trying to use the version of the standalone collector that came bundled with the installation of Visual Studio 2015. If that's indeed the case, the CLSID that you need is {AAAAAA70-DFED-4CB4-A1D6-920F51E9674A}.
The IntelliTrace standalone collector is both backwards and forwards compatible. You are not gaining anything by using the one bundled with VS 2015 compared to the one that this blog post links to and is available on the download center http://www.microsoft.com/…/details.aspx
Once we have updated download center I will update this blog post with the new CLSID as well.
We have stumbled upon the same issue as other posts here: Loading profiler failed. COR_PROFILER is set to an invalid CLSID: '{2AA1AA98-2CAA-4FCF-86CE-EFA007737E83} '. HRESULT: 0x80070057. Process ID (decimal): 5096. Message ID: [0x2502]."
The reason for the error is that our service is 64bit which in turn requires to change the COR_PROFILER_PATH to the x64 directory. In this example COR_PROFILER_PATH=<Path_where_collector_was_extracted>x64Microsoft.IntelliTrace.Profiler.12.0.0.SC.dll. Mine for instance is c:intellitracecollectorx64Microsoft.IntelliTrace.Profiler.12.0.0.SC.dll
Problem resolved!
I am running into same problem that many others stumbled upon and I don’t know what I am doing wrong. I downloaded the standalone collector from the link provided in this article. Below are the entries I created for the Environment variable in the registry. The service I am trying to trace is a x64.
COR_ENABLE_PROFILING=1
COR_PROFILER={AAAAAA70-DFED-4CB4-A1D6-920F51E9674A}
COR_PROFILER_PATH=”C:IntelliTraceCollectorx64Microsoft.IntelliTrace.Profiler.14.0.0.SC.dll”
VSLOGGER_CPLAN=”C:IntelliTraceCollectorcollection_plan.MyService.trace.xml”
The collection_plan.MyService.trace.xml has following entry.
C:IntelliTraceLogFiles
Everyone has Full Control on both C:IntelliTraceLogFiles and C:IntelliTraceCollector folders.
When I restart the service, I see following entry in events log
.NET Runtime version 4.0.30319.0 – Loading profiler failed. COR_PROFILER is set to an invalid CLSID: ‘{AAAAAA70-DFED-4CB4-A1D6-920F51E9674A} ‘. HRESULT: 0x80070057. Process ID (decimal): 16636. Message ID: [0x2502].
Not sure if it matters but I do have Visual Studio 2015 installed on this machine. However I would like to use Standalone collector for trace collection. Any help will be greatly appreciated.
I am running into same problem that many others stumbled upon and I don’t know what I am doing wrong. I downloaded the standalone collector from the link provided in this article. Below are the entries I created for the Environment variable in the registry. The service I am trying to trace is a x64.
COR_ENABLE_PROFILING=1
COR_PROFILER={AAAAAA70-DFED-4CB4-A1D6-920F51E9674A}
COR_PROFILER_PATH=”C:IntelliTraceCollectorx64Microsoft.IntelliTrace.Profiler.14.0.0.SC.dll”
VSLOGGER_CPLAN=”C:IntelliTraceCollectorcollection_plan.MyService.trace.xml”
The collection_plan.MyService.trace.xml has following entry.
C:IntelliTraceLogFiles
Everyone has Full Control on both C:IntelliTraceLogFiles and C:IntelliTraceCollector folders.
When I restart the service, I see following entry in events log
.NET Runtime version 4.0.30319.0 – Loading profiler failed. COR_PROFILER is set to an invalid CLSID: ‘{AAAAAA70-DFED-4CB4-A1D6-920F51E9674A} ‘. HRESULT: 0x80070057. Process ID (decimal): 16636. Message ID: [0x2502].
Not sure if it matters but I do have Visual Studio 2015 installed on this machine. However I would like to use Standalone collector for trace collection. Any help will be greatly appreciated.
Actually carefully looking at my earlier reported issue, I figured there was an extra space in my CLSID. After fixing that, now I am getting a different issue. Upon starting the service, now I see following reported in event logs
.NET Runtime version 4.0.30319.0 – Loading profiler failed during CoCreateInstance. Profiler CLSID: ‘{AAAAAA70-DFED-4CB4-A1D6-920F51E9674A}’. HRESULT: 0x8007007e. Process ID (decimal): 16280. Message ID: [0x2504].
Completely disregard my earlier comments. Removing double quotes in path fixed my last issue. Sorry about spamming your post. It clearly works 🙂