ASP.NET MVC Tracing Issues -


question

how asp.net mvc trace information consistent in-page trace output trace.axd? may missing obvious, please call out if see it.

background info traditional asp.net

so in regular asp.net days, add following web.config:

<system.diagnostics>     <trace>         <listeners>             <add name="webpagetracelistener" type="system.web.webpagetracelistener, system.web, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a"/>         </listeners>     </trace> </system.diagnostics> ... <system.web>     <trace enabled="true" pageoutput="true" writetodiagnosticstrace="true"/> ... <system.codedom>     <compilers>         <compiler language="c#;cs;csharp" extension=".cs" warninglevel="1" compileroptions="/d:trace" type="microsoft.csharp.csharpcodeprovider, system, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"> 

then add following in pages:

httpcontext.current.trace.write("write trace here"); or system.diagnostics.trace.write("write trace here"); 

and if hit page (i.e. localhost:61115/default.aspx), nice trace table custom trace embedded asp.net page events:

aspx.page begin load 0.00343 0.000357 test 0.00462176 0.001192  aspx.page end load 0.00526904 0.000018  

hitting localhost:61115/trace.axd?id=0 retain same trace results in-page trace outputs.

background info on asp.net mvc

unfortunately, cannot work in asp.net mvc 2.0 reasons unknown me. use similar web.config settings ones listed above. interesting can traces partially work. if hit functionality equivalent default page (aka index action method of homecontroller), see of traditional asp.net page events such preinit, preload, prerender, etc no custom trace msg using either system.diagnostics nor httpcontext.trace.write.

however, if turn trace.axd?id=0 file, i'm greeted custom trace messages no asp.net page event trace output. must missing here causing inconsistency in trace information see in-page vs. trace.axd (recall traditional asp.net outputs identical in-page vs. trace.axd outputs). have in-page trace information consistent trace.axd (either removing traditional asp.net page events or other means). there missing?

quoting directly book "mvc 2 in action":

when called trace.write() in web forms, interacting trace- context class. exists on viewpage in asp.net mvc, isn’t want write tracing statements. time you’ve passed baton on view, there’s no logic there you’d need trace. instead, you’d trace logic embedded in controllers. might try leverage tracecontext class in controller, these statements won’t ever make way list of messages in trace log (on page or on trace.axd). instead, can use system.diagnostics.trace , set own tracelisteners inspect activity in controllers. alternatively, can leverage more mature logging framework such log4net or nlog:

you debug asp.net mvc applications .net application. tracing, however, doesn’t offer mvc. instead, can lean on built-in tracelisteners in .net, or utilize logging library mentioned earlier. aspect of error logging health monitoring.

sorry not answering in own words, think explanation spot on :)


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -