How to customize the trace output?



How to customize the trace output?..

Answer / Gaurav Kaushik

To customize the trace output in .NET, you can use the System.Diagnostics namespace. Here's a basic example of how to initialize a TraceSource and write custom messages: nn```csharpnusing System; using System.Diagnostics;npublic class CustomTrace : TraceSource {n public CustomTrace() : base("CustomTraceSource") {n Listeners.Add(new TextWriterTraceListener("trace.txt"));n }n public void LogInfo(string message) {n TraceEvent(TraceEventType.Information, 0, message);n }n}nclass Program {n static void Main() {n var customTrace = new CustomTrace();n customTrace.LogInfo("This is a custom trace message.");n }n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Dot Net General Interview Questions

Please explain what garbage collection is and how it works. Provide a code example of how you can enforce garbage collection in .net?

1 Answers  


Which ports are used by virueses?

1 Answers  


Explain how garbage collection works?

1 Answers  


Explain the features that are common to all .Net languages.

1 Answers   Accenture,


Explain how to redirect tracing to a file?

1 Answers  


What is Polymorphism? How does VB.NET/C# achieve polymorphism?

1 Answers  


Differentiate between 'DataSet' and 'SQLDataReader' in ADO.NET?

1 Answers   QuestPond,


How can you turn-on and turn-off cas?

1 Answers  


What is RunTime Polymorphism?

5 Answers   Deloitte, eClerx, Horizon, Intel, Pragna Technologies,


What is smart navigation in .net?

1 Answers  


What is the difference between odbc and ado?

1 Answers  


Name some of the languages .NET support?

3 Answers  


Categories