TraceEvent() public method

public TraceEvent ( TraceEventCache eventCache, String source, TraceEventType eventType, int id, string format ) : void
eventCache TraceEventCache
source String
eventType TraceEventType
id int
format string
return void
		public void TraceEvent2 ()
		{
			StringWriter sw = new StringWriter ();
			XmlWriterTraceListener x = new XmlWriterTraceListener (sw);
			x.TraceEvent (null, "bulldog", TraceEventType.Error, 5);
			x.Close ();
			Assert.AreEqual (sample3.Replace ('\'', '"'), sw.ToString ());
		}
示例#2
0
        static void Main(string[] args) {
            _execTimer.Start();

            try {
                Delay(10);
                LogLongExec("Delay(10)");
                Delay(5000);
                LogLongExec("Delay(5000)");
            } catch (Exception ex) {
                using (
                    XmlWriterTraceListener log1 =
                        new XmlWriterTraceListener($@"C:\Users\{Environment.UserName}\Pictures\Error.log")) {
                    log1.TraceEvent(new TraceEventCache(), ex.Message, TraceEventType.Error, ex.HResult);
                    log1.Flush();
                }
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            WriteLine("Option 1");
            System.Diagnostics.TraceSource trace = new TraceSource("./1_Trace.log");
            trace.TraceEvent(TraceEventType.Error, 123, "Option A: System.Diagnostics.TraceSource trace");

            WriteLine("Option 2: writes a file as 'TraceEventType.Error' and source 'Option B...'");
            using (System.Diagnostics.XmlWriterTraceListener log1 = new XmlWriterTraceListener("./2_Error.log"))
            {
                log1.TraceEvent(new TraceEventCache(), "Option B: System.Diagnostics.XmlWriterTraceListener", TraceEventType.Error, 123);
                log1.Flush();
            }

            WriteLine("Option 3");
            WriteLine("Throws: An unhandled exception of type 'System.Security.SecurityException' occurred in System.dll");
            //System.Diagnostics.EventInstance errorEvent = new EventInstance(123, 1, EventLogEntryType.Error);
            //EventLog.WriteEvent("MyAppErrors", errorEvent, "the message");

            WriteLine("Option 4: writes to the EventLog");
            EventLog logEntry = new EventLog();
            logEntry.Source = "Application";
            logEntry.WriteEntry("the message", EventLogEntryType.Error);


            WriteLine("Option 5: writes a file as 'TraceEventType.Information' and source 'Trace'");
            System.Diagnostics.XmlWriterTraceListener listener = new XmlWriterTraceListener("./5_Errror.log");
            listener.WriteLine("the log message");
            listener.Flush();
            listener.Close();

            // See Output window:
            // Error.log: a trace message
            WriteLine("Option 6: Trace.WriteLine with 'Error.log' as category");
            Trace.WriteLine("a trace message", "Error.log");

            WriteLine("Done");
            ReadLine();
        }