DEV Community

Matthew Cullen
Matthew Cullen

Posted on

1 1

Read/Write to Files in C# with errorLogging example

https://github.com/3Mustard/cSharpCliErrorLogger

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>();
errors.Add(err2);
errors.Add(err3);

eLogger.LogNewError(err);
eLogger.LogAllNewErrors(errors);
eLogger.DisplayErrorsToConsole();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more