[Original] Tracking the code of the code in C # .NET

xiaoxiao2021-03-06  56

Author: bluesky35 (blue) 1 The following code tracking methods using System.Diagnostics; namespace CorePlus.Framework.Utility {public class LogUtility {// listener private static TextWriterTraceListener listner = null; // output trace file private const string Trace_file = "c: //trace.log"; // traceName is the track name, TraceMessage is the tracking content public static void trace (String traceName, String TraceMessage) {// Variable Definition StringBuilder Message = NULL; // Register listener IF (Listner == NULL) {Try {// Generates Listener Listner = New TextWritertraceListener (Trace_File);

// Add the listener system.diagnostics.trace.listeners.add (listner);

// Set the listener system.diagnostics.trace.indentLevel = 0; system.diagnostics.trace.autoflush = true;} catCH (system.exception) {return;}}

// Output Tracking Content Message = New StringBuilder ();

// Praque information // Today time message.append ("["); message.append (datetime.now); message.Append ("]); // Identify name message.Append (" ["); message. Append (tracename); message.Append ("]"); // Listening Information Message.Append (TraceMessage);

// Output listening content to file system.diagnostics.trace.writeline ());}}} 2. Calling this method directly in Form can private void button1_click (Object Sender, System.EventArgs E) { Logutility.trace ("Button1_Click", "Enter button1_click event");} C: /TRACE.LOG file records all code trends

转载请注明原文地址:https://www.9cbs.com/read-113834.html

New Post(0)