Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hallo everybody,
my english is not so good as it should be, but i will try to formulate my question as good as possible so everybody can understand it. Smile | :)
 
My question:
 
In my firm, we have several process which are lunched from one service. Most of the process throw Trace messages,so we have the possible to see, what the programm is doing.
Now I want to capture this Traces.
I have written a program which is similar too the open source program DebugViewer. If the processes are started local everything works fine and my program can capture the messages.
But when I start the process from a service my DebugViewer can not capture the messages any more.
 
Maybe somebody has a solution for me Smile | :)
 
Thank you for every help.
 
P.S. It maybe will takes several days until i will answer back. Smile | :)
 
Kind regards BaronEK Smile | :)
Posted 11-Jan-13 4:36am
BaronKE355
Comments
Sergey Alexandrovich Kryukov at 11-Jan-13 11:35am
   
Do you have access to these processes' source code? To change the way the data you need it traced. Because, otherwise, it this trace goes nowhere, it goes nowhere; you cannot do much about it.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The mere fact that you start separate processes from you Windows Service processes looks very questionable. Separate processes are very well isolated, so they are hard to control. I can guess that one of the reasons for such architecture is the possibilities for independent debugging (I can guess that you do it, from the context of your question). I would understand it but… there are much, much better ways.
 
But this is not a main point. Please see my comment to the question. If you cannot modify the tracing designed to be used by DebugViewer or similar facility, you cannot do much about it. If you can modify this tracing code, you should do it. One of the way is using the class System.Diagnostics.EventLog instead:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[^].
 
This is the very universal way of logging suitable to any way you host the code, including the service host, which is a very special way. It is also very dependable.
This way, you can direct your logs to different sinks, depending on your configuration, but by default if will go to the system log viewable by the system "Event Viewer" applet: eventvwr.msc.
You also can create your own viewers. You can simply redirect logs to a file, or anything at all.
 
If you use the system event log, you can also isolate log coming from you product of company's set of products to a separate tree. Please see my past answers on this topic:
how to log in a separate tree structure: How to create event log under a folder[^],
how to make a custom logger: MsBuild OutPut to the TextBox on the fly in Windows Application[^].
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hallo Sergey Alexandrovich,
First at all thank you for your comment.
After some more researchs on the web, I have found a way to get my trace messages such as I wanted.
I am now using the kernel32.dll to create DBWIN_Buffer and DBWIN_DATA events and to capture the traces massages of other applications.
The method CreateEvent of kernel32 longs for a name. So I can pass the words "DBWIN_BUFFER_READY" and "DBWIN_DATA_READY" to create two events. Defaultly it sets a "local" behind the two words, so the method interptrets it as "Local\DBWIN_BUFFER_READY", when i change it to "Global\DBWIN_BUFFER_READY" I´m getting the possibility to capture the traces of an service.
Here is a link which help me a lot. Maybe you wanna look at it.
 
http://unixwiz.net/techtips/outputdebugstring.html
 
Still thank you for your comment. It was the way I wanted to go if I would not find an other possibility. Smile | :)
 
Here is the main block of my code:
 

//Creates the Event for slot 'BUFFER_READY'
       p_brEvent = CreateEvent(ref sa, false, true, "Global\\DBWIN_BUFFER_READY");
           if (p_brEvent == IntPtr.Zero)
           {
               throw new CreateEventException("Failed to create event (DBWIN_BUFFER_READY)");
           }
 
       //Cretes the Event for slot 'DATA_READY'
           p_drEvent = CreateEvent(ref sa, false, false, "Global\\DBWIN_DATA_READY");
 
       if (p_drEvent == IntPtr.Zero)
       {
           throw new CreateEventException("Failed to create event DBWIN_DATA_READY");
       }
 
       // Get a handle to the readable shared memory at slot 'DBWIN_BUFFER'
       // Creates an Object and writes the name of it in the file system, so other processes can work with it.
       p_sfEvent = CreateFileMapping(new IntPtr(-1), ref sa, PageProtection.ReadWrite, 0, 4096, "Global\\DBWIN_BUFFER");
       if (p_sfEvent == IntPtr.Zero)
       {
           throw new CreateEventException("Failed to create a file mapping to slot DBWIN_BUFFER");
       }
 

       //File which contains the Debug Messages will me mapped into the virtuel shared
       //memory of the processes, so both processes can work with it directly in the memory
       map_shEvent = MapViewOfFile(p_sfEvent, SECTION_MAP_READ, 0, 0, 512);
       if (map_shEvent == IntPtr.Zero)
       {
           throw new CreateEventException("Failed to create a file mapping to slot DBWIN_BUFFER");
       }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100