Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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. :)

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 :)

Thank you for every help.

P.S. It maybe will takes several days until i will answer back. :)

Kind regards BaronEK :)
Posted
Comments
Sergey Alexandrovich Kryukov 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

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
 
Share this answer
 
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. :)

Here is the main block of my code:

C#


C#
//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");
       }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900