Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write to a file multiple times

Tags:

c#

io

I want to write a debug log file for my app.

I don't want to use NuGet because I have a log4net installation and it has caused problems.

I want to write a simple .log file so that I can add content through the process

I need something like:

System.IO.File.WriteAllText(path + ".log", "<some text>,");

 // some lines of code here

System.IO.File.WriteAllText(path + ".log", "<more text>");

When I will open the log file I want to see: <some text>,<more text>


2 Answers

If you want to append (not rewrite) then put Append instead of Write:

 ...

 System.IO.File.AppendAllText(path + ".log", "<more text>");
like image 171
Dmitry Bychenko Avatar answered Jan 20 '26 04:01

Dmitry Bychenko


Do you mean to simply append? If so, you can simply use:

System.IO.File.WriteAllText(path + ".log", "<some text>,");

 // some lines of code here

System.IO.File.AppendAllText(path + ".log", "<more text>");
like image 28
Mithrandir Avatar answered Jan 20 '26 03:01

Mithrandir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!