EzDevInfo.com

tracing.js

A small JS library that makes it possible to trace function calls.

How to make DebugView work under .NET 4?

SysInternals' DebugView no longer works if used under .NET 4. Some research indicated that the new architecture of the framework did not allow for traces to be captured if a debugger was attached; in my case it's the Visual Studio debugger. Changing target framework from 4 to 3.5 makes it work again.

Anybody knows a way of getting DebugView to work under .NET 4 while having the Visual Studio debugger attached? I tried clearing the Listeners collection of the Trace class, but no luck.


Source: (StackOverflow)

What is the performance impact of tracing in C# and ASP.NET?

I found this in some production login code I was looking at recently...

HttpContext.Current.Trace.Write(query + ": " + username + ", " + password));

...where query is a short SQL query to grab matching users. Does this have any sort of performance impact? I assume its very small.

Also, what is the purpose of this exact type of trace, using the HTTP Context? Where does this data get traced to? Thanks in advance!


Source: (StackOverflow)

Advertisements

C++: How to count all instantiated objects at runtime?

I have a large framework consisting of many C++ classes. Is there a way using any tools at runtime, to trace all the C++ objects that are being constructed and currently exist?

For example, at a certain time t1, perhaps the application has objects A1, A2 and B3, but at time t2, it has A1, A4, C2 and so on?

This is a cross platform framework but I'm familiar with working in Linux, Solaris and (possibly) Mac OS X.


Source: (StackOverflow)

Does java have any mechanism for a VM to trace method calls on itself, without using javaagent, etc?

I want to build call graphs on the fly, starting at an arbitrary method call or with a new thread, which ever is easier, from within the running JVM itself. (this piece of software is going to be a test fixture for load testing another piece of software that consumes call graphs)

I understand there are some SPI interfaces, but it looks like you need to run -javaagent flag with them. I want to access this directly in the VM itself.

Ideally, I'd like to get a callback for entry and exit of each method call, parameters to that method call, and time in that method. Within a single thread obviously.

I know AOP could probably do this, but I'm just wondering if there are tools within the JDK that would allow me to capture this.


Source: (StackOverflow)

TraceSwitch and SourceSwitch - what's the difference?

So I'm probably missing the obvious here, but what actually is the difference between the functionality of the TraceSwitch and SourceSwitch classes?

They both give identical summary descriptions:

Provides a multilevel switch to control tracing and debug output without recompiling your code.

Are the Remarks sections are oddly similar to my eyes. Could someone please clarify the difference in their functionality and usage cases?

(For completeness, I'm using switches with my TraceSource object, rather than the old static Trace class, though I doubt it makes much difference.)


Source: (StackOverflow)

Guidelines for logging (tracing) in a Windows application

As I see it there are two different types of logging:

  • User-focused logs, like those produced by my anti-virus ("started scan", "no threats found", etc.)
  • Developer-focused traces, which may be as simple as a log of exceptions or as detailed as a log of every method call

I'm currently planning how to incorporate the second type of logging into our application, so that we are able to get some record of what went wrong when a user reports a problem. I've seen several discussions of how verbose these traces should be and of available frameworks, but here I'm looking for some more general guidelines.

Particular questions I have include:

  • Should we be logging to a file, to the Windows Event Log or somewhere else? For these developer-focused logs that are probably of no interest to the user, I feel that a file would be most appropriate. But in that case:

    • Where should the file be located?
    • Should we implement some form of log rotation to prevent the file growing too large?
    • How can we handle multiple instances of the application accessing the log simultaneously?

  • Should this tracing be switched on by default? If it is, I am a little concerned about performance; but if it is not, will we end up responding to many users' issues with "turn on tracing and try to reproduce the problem"? This doesn't sound too helpful.

I hope you can help me with these questions. I'd also appreciate any other advice you have on this topic.


Source: (StackOverflow)

Tracing versus Logging and how does log4net fit in?

I am wondering about what the difference between logging and tracing is.

Is the difference basically that tracing is more detailed log giving developers a tool to debug applications at runtime?

I have been experimenting with log4net and doing logging. Now I am wondering if I should be doing tracing as well and if I could/should use log4net for that purpose. Should I be doing tracing with log4net and is there some trace level for log4net loggers? Should I use a different log level for debug and trace purposes or is it ok to use the same? Can you give a simple example on how I would do logging and tracing for a simple method?

Edit: Despite a few helpful answers below I am still unsure how I should be doing tracing versus logging.

I have the following method in my Business layer and I want to add logging/tracing to it. I am wondering how to do it efficiently. Is the following method acceptable in terms of logging/tracing? Should the log messages be of type Info instead of Debug? Are the Debug messages I am logging considered trace? How would you change it?


IEnumerable<Car> GetCars()
{
   try
   {
      logger.Debug("Getting cars");
      IEnumerable<Car> cars = CarAccessor.GetCars().ConvertAll(DataAccessToBusinessConverter);
      logger.Debug("Got total of " + cars.Count + " cars"); 
   } catch (Exception e) {
      logger.Error("Error when getting cars", e);
      throw new Exception("Unexpected error when getting cars");
   }
}


Source: (StackOverflow)

Better way to make a bash script self-tracing?

I have certain critical bash scripts that are invoked by code I don't control, and where I can't see their console output. I want a complete trace of what these scripts did for later analysis. To do this I want to make each script self-tracing. Here is what I am currently doing:

#!/bin/bash
# if last arg is not '_worker_', relaunch with stdout and stderr
# redirected to my log file...
if [[ "$BASH_ARGV" != "_worker_" ]]; then
    $0 "$@" _worker_ >>/some_log_file 2>&1  # add tee if console output wanted
    exit $?
fi
# rest of script follows...

Is there a better, cleaner way to do this?


Source: (StackOverflow)

WCF: How do I trace message bodies?

I'm trying to diagnose a WCF service that is self-hosted in a relatively simple service host process (Service.exe).

I have Service.exe.config configured thus:

<?xml version="1.0" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" 
              switchValue="All"
              propagateActivity="true">
        <listeners>
          <add name="traceListener" 
               type="System.Diagnostics.XmlWriterTraceListener" 
               initializeData= "c:\temp\Service.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <system.serviceModel>
    <diagnostics>
      <messageLogging maxMessagesToLog="1"
                      maxSizeOfMessageToLog="2147483647"
                      logEntireMessage="true"
                      logMessagesAtServiceLevel="true"
                      logMalformedMessages="true"
                      logMessagesAtTransportLevel="true">
      </messageLogging>
    </diagnostics>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0"
                      sku=".NETFramework,Version=v4.0" />
  </startup>
</configuration>

When I look at the resulting svclog file, I see many trace events being logged (I expected only the first message to be logged), and none of the messages being traced show a message body (only headers).

I'm sure I must be missing something simple here, but I don't see it.

UPDATE: When I look at the WCF Config Editor, there are two sections under "Diagnostics": MessageLogging and Tracing. When I click the "EnableMessageLogging" link, my config file gets updated:

  <system.diagnostics>
    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="All">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add initializeData="c:\temp\MessageBodyTracing.svclog" type="System.Diagnostics.XmlWriterTraceListener"
            name="traceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="c:\users\me\documents\visual studio 2010\projects\messagebodytracing\messagebodytracing\app_messages.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>

I guess the source named System.ServiceModel.MessageLogging is the key - I hadn't seen that in any documentation of message tracing...


Source: (StackOverflow)

Consuming "Event Tracing for Windows" events

An answer to this question has led me to look into using "Event Tracing for Windows" for our tracing needs. I have come across NTrace, which seems to be a good way to produce ETW events from C# code (using the XP-compatible "classic provider" model).

However, I am unable to find an easy way to consume these events - to see them in real-time and/or log them to a file. The only way I have found is that described in the NTrace documentation: using a tool which is only available as part of the Windows DDK.

In the case of a complex problem in the field, we may need to ask the user to produce a file containing a trace. We can't ask users to download the DDK or carry out a number of complex operations in order to do this.

Is there a straightforward, user-friendly way to log ETW events to a file?

Also, is it possible for someone to consume ETW events on Windows Vista/7 if they are not running as administrator?


Source: (StackOverflow)

I cannot start Azure Diagnostic Monitor

I'm trying to test the Azue diagnostic monitor in a cloud solution with a single asp.net application.

I get an exception every time I try to start the diagnostics monitor:

        CloudStorageAccount account = CloudStorageAccount.Parse("UseDevelopmentStorage=true");

        Write(account.TableEndpoint.AbsoluteUri);

        // Get default initial configuration.
        var config = DiagnosticMonitor.GetDefaultInitialConfiguration();

        config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined;
        config.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(5);

        // Start the diagnostic monitor with the modified configuration.
        DiagnosticMonitor.Start(account, config); // Exception

The exception says:

System.ArgumentException was unhandled by user code
  Message=Directory C:\Users\Me\Documents\Visual Studio 2010\Projects\CloudDebuggingTest\CloudDebuggingTest\bin\Debug\CloudDebuggingTest.csx\roles\CloudDebuggingTest.Web\diagnostics\x64\monitor does not exist.
  Source=Microsoft.WindowsAzure.Diagnostics
  StackTrace:
       at Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.ValidateStartupInfo(DiagnosticMonitorStartupInfo startupInfo) in :line 0
       at Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.StartWithExplicitConfiguration(DiagnosticMonitorStartupInfo startupInfo, DiagnosticMonitorConfiguration initialConfiguration) in :line 0
       at Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.Start(CloudStorageAccount storageAccount, DiagnosticMonitorConfiguration initialConfiguration) in :line 0
       at CloudDebuggingTest.Web._Default.StartDiagnostics() in C:\Users\Me\Documents\Visual Studio 2010\Projects\CloudDebuggingTest\CloudDebuggingTest.Web\Default.aspx.cs:line 48
       at CloudDebuggingTest.Web._Default.Page_Load(Object sender, EventArgs e) in C:\Users\Me\Documents\Visual Studio 2010\Projects\CloudDebuggingTest\CloudDebuggingTest.Web\Default.aspx.cs:line 19
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

I have no idea about what am I missing, I've been checking out some links and they do exactly this. Any idea?

Cheers.


Source: (StackOverflow)

ASP.Net excessive use of User Controls

I'm investigating an asp.net web application that extensively uses User Controls on each page. Most pages contain around 10-20 user controls. The User controls seem to be the visual representation of the business objects (if that makes sense), although at a finer granularity such as each tab of a tab control having its contents in a user control. The project itself has over 200 user controls (ascx files).

The performance of the application is very poor (and the reason I'm investigating). Each event (such as a click or dropdown selection etc) requires about 5 seconds for the page to load (10 seconds whilst in visual studio). The application has no use of Ajax.

Tracing is painful as the aspx pages themselves have no code in the code-behind as the user controls look after all of this, so tracing a single page requires trace statements in all the user controls that are on that page.

I actually think that having each user control look after its business code and being re-usable is a smart idea, but is an excessive use of user controls going to incur a performance hit? Does this seem like the structure of an asp.net application that was written by someone with a strong WinForms background?

EDIT
thought I should add that i'm not questioning the use of user controls (or even the amount) but simply whether having so many on a page that all accomplish things (each user control connects to the database for example) will generally cause performance problems...For example, if just one user control postsback to do something, what about the processing of all the others, some are visible and some aren't...@David McEwing mentioned that he had 40 optimised user controls performing etc, but if the developer was WinForms based or "not familiar with asp.net", then how are they going to make sure each one is optimised...

EDIT2
After getting a sql statement trace, the same calls for data are being executed 5-6 times per page call for each event as the different user controls require data that is not stored commonly e.g. each user control in the tab (mentioned above) makes the same call to populate an object from the database...I'm really not here to accuse user controls of being the problem (should i delete the question?) as clearly the problem is NOT user controls but with the use of them in this particular case...which I believe is excessive!


Source: (StackOverflow)

At what stage do you add logging & tracing in OO?

I'm interested at what stage in your development do add logging and/or tracing to your applications?

I'm working with a .Net stack and log4net (via commons.logging). Generally taking a TDD approach to development although admittedly not 100%, sometimes Im know to spike out without test coverage. My application all sit server-side, e.g. web services, windows service that consume messages off a bus, asp.net mvc business admin apps. etc..

I found myself decorating methods in my applicatiosn services with descriptive logger.INFO "Getting cakes from repository" . some work .. "Got 5 cakes from repository. ", and then an unhandled expcetion handler for the app doamin to logger.FATAL for unexpected excpetions that bubble up.

However I usually end up going back and applying these near the end of development rather than at the start of development and I might have a dozen or two only. I find I rarely decorate any lower level classes such as implementation of ICakeRepository with logger stuff as it seems pointless.

For tracing, which switched on via config, I'm thinking of intercepting method calls and instance creation using the IOC framework, and this should take care of on-site troublehsooting rather than heavy trace population.


Source: (StackOverflow)

WCF Tracing From Code

I have all of my connections set up from my code, as opposed to using my config file. How does one go about setting up WCF Tracing on a connection built from code. I tried adding the tracing to the config file, as explained here, but it produces no logs whatsoever.

I need to know either how to make it work from the config file for connections set up in code, or how to configure it manually in code if anyone has any info. Thanks!

EDIT: To add a little more information:

The application is a C# Console application, and my binding is declared as:

private Binding getBinding()
{
    NetTcpBinding tcp = new NetTcpBinding();
    tcp.ReaderQuotas.MaxArrayLength = 65535;
    tcp.TransferMode = TransferMode.Streamed;
    tcp.ReaderQuotas.MaxArrayLength = int.MaxValue;
    tcp.ReaderQuotas.MaxDepth = int.MaxValue;
    tcp.ReaderQuotas.MaxStringContentLength = int.MaxValue;
    tcp.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
    tcp.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
    tcp.MaxReceivedMessageSize = int.MaxValue;
    return tcp;
}

And I then add services to my app using a generic function:

private List<ServiceHost> m_Hosts = new List<ServiceHost>();
private static List<string> m_Services = new List<string>();

public void AddHost<T1, T2>(string uri)
    where T1 : class
    where T2 : class
{
    m_Services.Add("net.tcp://<ipaddress>:<port>/" + uri);
    m_Hosts.Add(new ServiceHost(typeof(T1)));
    m_Hosts[m_Hosts.Count - 1].AddServiceEndpoint(typeof(T2), getBinding(), m_Services[m_Services.Count - 1]);
}

There's obviously a little more code to make this all work, but this should give any relevant parts.


Source: (StackOverflow)

wcf trying to set up tracing to debug, not writing to log file

here's my web.config, running a WCF service in an application on IIS7, but nothing is being written to the specified file. permission on the file has been granted for everyone.

<system.diagnostics>
  <sources>
   <source name="System.ServiceModel" switchValue="Information, ActivityTracing,     error, warning, critical" propagateActivity="true">
    <listeners>
     <add name="traceListener"
  type="System.Diagnostics.TextWriterTraceListener"
  initializeData="c:\log\tracestext.log" />

    </listeners>
  </source>
  </sources>
 </system.diagnostics>

I can add a service reference just fine.
I then try to call the service from a windows app and, after a few minutes, get an error on the machine running the windows app "Client is unable to finish the security negotiation within the configured timeout (00:00:00). The current negotiation leg is 1 (00:00:00)."

but absolutely nothing is written to the trace log file specified in config.

Is there something else I need to do to enable tracing? thanks for your help

EDIT: "sources" section now matches the section recommended here: http://msdn.microsoft.com/en-us/library/aa702726.aspx

I've added the "diagnostics . messagelogging" section to "system.servicemodel"

and the event viewer shows: "Message Logging has been turned on. Sensitive information may be logged in the clear, even if it was encrypted on the wire: for example, message bodies. Process Name: w3wp Process ID: 1784 "

but the log file is still empty


Source: (StackOverflow)