I'm using .NET's built-in Tracing mechanism to trace program execution. The problem is the trace file can grow to several MB very quickly. Is there an efficient way of truncating the file when it grows past a certain point? I thought of putting in a check whenever something gets written (I have a custom class that inherits from TraceListener) but that might degrade performance too much. Maybe a Timer would be a better solution?
Anyone have any ideas?
Implement a custom trace listener:
Let's see how we can solve fairly common task: managing continuously generated trace files. Default trace listener implementation is not really suitable for service applications that are supposed to be always active. If application produces a lot of trace output, then sooner or later this information will use up all disk space.
http://www.codeproject.com/KB/dotnet/customnettracelisteners.aspx?display=Print
With this example, you are able to create log chunck like this:
MyTrace.txt (recent trace information);
MyTrace00.txt (trace history backup);
MyTrace01.txt (trace history backup);
and so on...
Of course, you can throw backup files away.
(Just a hint: try log4net (here) and Enterprise Library Logging Block (here)!)
Perhaps use an Event Log trace listener, since the EventLog can be easily automatically cycled in this way.
Related
I have an ASP.NET web application developed in C# and .Net v4. When you login in and leave for the page for some 15-20 minutes, I get the "Insufficient stack to continue executing the program safely."
According to my knowledge, there is no way you can try-catch the stackoverflow in .Net. I would imagine that recursive loading of web page and active session checking leading to this error (maybe a bad coding practice). I have also added the screenshot as i am able to figure it out from Stack trace. If anyone help me in this,it will be helpful.
I think I have found the solution. Still the test. Check this Link and this
they really looks promising. I will keep you guys updated when I succeed..
Thank you all for your help.
The problem is this callstack is right at the end of the stack.
A few things to look for:
Is there anywhere in your code where you are using .FindControl(string id)?
If so, is it locating a control and then trying to locate it further?
Are you dynamically creating controls, like for <asp:Placeholder/> controls.
It can be recursive when you reference the parent from within a nested control, which then gets re-referenced by the parent.
i am using file upload on the user front. is there any way if some exception occurs the html file control is able to persist its value on post back(i know it can't) but any work around?. i am using server side validations.
This could get messy.
Just a couple of points,
If an exception occurs do you really think it is wise to save the file?
By its nature an exception is telling you an error has occurred and processing should not continue. I would think the only time you should save the file is when you can recover or handle the exception without any side affects.
In which case you have to ask yourself, can you not just prevent the exception in the first place?
Always, always do validation on BOTH client and server side.
Why? Well to prevent this sort of thing, at least as much as possible. Let the user know there is a problem before posting, much better experience for them.
It terms of the problem, the best thing you could do is potentially keep the file path, and if an error occurs put that value back into the input box.
This wont be pretty, the input type for files is one of those special cases where the browser is responsible for a lot of the user interaction.
Remember in most cases what is happening is the browser is collection the byte information from the file and passing that around as part of the request, this is not something you are going to be able to manipulate easily.
An existing (though incomplete) FLEX3 project was given to us to finish (always a nightmare).
It is quite small but highly abstracted (contains well over 150 files to support only about 10 page views). I'm attempting to trace a single mouseclick event through this maze.
Is there a way to print out an actionscript trace and/or component flow using the debugger (or any other tool that anyone knows of)?
The flash.txt file appears worthless since it doesn't contain ActionScript calls and/or component flows.
Thanks
This will print your execution graph:
Trace.setLevel(Trace.METHODS, Trace.LISTENER);
Trace.setListener(handleMethods);
function handleMethods(fqcn:String, lineNumber:uint, methodName:String, methodArguments:String):void
{
trace(methodName);
}
Oof. Yeah, always.
The Profiler might give you useful information, but you need to pay for FlexBuilder Pro to get it, if you don't already have it. I'm not real handy with the Profiler, so I may be off base with that advice. It would be worth checking into, though, if you are already familiar with other profiling tools.
I would probably just start looking at every point that .addEventListener(MouseEvent.CLICK occurs in the code - and .addEventListener("click", just in case the previous developer chose not to use the constant, for some reason.
Obviously, that could show up a lot in 150 files, but that's how I would go about it.
I would also look at any custom events that could get into the mix. Because maybe the CLICK event is handled at some point and the handler dispatches a custom event. And maybe the handler for that custom event dispatches another custom event. Or dispatches a MouseEvent.CLICK event, etc.
Hope that helps. Good luck...
Check out
http://jpauclair.net/2010/02/10/mmcfg-treasure/
esp.
AS3Trace = 1|0
This one is also very useful for
debugging It trace every single call
to any function that is being called
in the SWF at runtime! It’s like
expending the StackTrace to the full
software run time.
And many more.
This probably has an easy answer, but I haven't been able to find one yet. I was wondering if there was a simple solution to exporting the page-level trace results of trace.axd to a log file of some sort.
Thanks
The <trace> element has a writeToDiagnosticsTrace option, which enables you to capture trace events with a trace listener.
We have done this, but with poor results. Because of incomplete trace support in ASP.NET, we couldn't get anything but the trace event messages into the file - no timestamps, no elapsed time - nothing really useful.
Have a look here it might take you some way to what you want:
http://www.15seconds.com/issue/020910.htm
I have seen several projects that use the Trace functionality to capture events and stream them out to a log file. I have been unsuccessful in finding a simple to follow guide that will show me how to configure Trace to capture and write said logfile. Does anyone have a link recommendations, or provide some simple steps to follow?
The Trace object writes the statements to any attached TraceListeners. You can build your own, but there are a number already defined in the System.Diagnostics namespace, including:
ConsoleTraceListener (Console)
DefaultTraceListener (Visual Studio / Debugger)
DelimitedListTraceListener (TextWriter, special formatting)
EventLogTraceListener (EventLog - anything that inherits from System.Diagnostics.EventLog)
TextWriterTraceListener (TextWriter - think file)
You can, of course, inherit your own from the TraceListener class that writes to where ever you want. For example, you could log to a database, have it send e-mails or pages in certain situations, or write the statements back to a logging platform like log4net.
The big thing is that you need to create an instance of whatever listeners you want and then add them to the Trace' class Listeners collection. You can add as many as you need and Trace will write to all of them. This way, you can write your logging code once using a well-supported and understood object that's part of the framework, and you can attach anything you need to it.
I stumbled into a MSDN article that really helps. Sorry I didn't find it before posting the question but perhaps others may have the same question and haven't found this link.
Take a look at logging frameworks. We rolled out own, but are now migrating over to log4net available free at http://logging.apache.org/log4net/
Im looking for a way to set the Category of the EventLog, the FormattedEventLogTraceListener writes into (not the category of the message).
But I can't find an appropriate property of this class.
Is it possible to set this?