TextWriterTraceListener Not Creating File

Nathan Sokalski 4,121 Reputation points
2022-10-01T17:54:41.183+00:00

I am attempting to use TextWriterTraceListener for the first time. I currently have the following code:

TextWriterTraceListener testresultslistener = new TextWriterTraceListener("MyOutput.txt");  
testresultslistener.WriteLine("My Output");  

However, it does not seem to be creating a file. What am I doing wrong?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,387 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 24,311 Reputation points Microsoft Vendor
    2022-10-05T02:41:30.82+00:00

    @Nathan Sokalski , based on my test, Viorel's code is correct. The output folder means that bin/debug folder, like the following:

    247540-image.png

    You also use the following code to get your current output path.

      string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);  
    

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.