DEV Community

Matthew Cullen
Matthew Cullen

Posted on


Read/Write to Files in C# with errorLogging example

Example of how to use ErrorLogger to write one or multiple errors to a file and display them in the console

string filePath = System.IO.Path.GetFullPath(@"..\logs.txt");
ErrorLogger eLogger = new ErrorLogger(filePath);

Error err = new Error();
Error err2 = new Error();
Error err3 = new Error();
err.Message = "new error message 1";
err.Date = DateTime.UtcNow.ToString();
err2.Message = "new error message 2";
err2.Date = DateTime.UtcNow.ToString();
err3.Message = "new error message 3";
err3.Date = DateTime.UtcNow.ToString();

List<Error> errors = new List<Error>();

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

50 CLI Tools You Can't Live Without

>> Check out this classic DEV post <<