Conversation
prashant1shukla
commented
May 11, 2024

| using System; | ||
| using System.IO; | ||
|
|
||
| public class Logger : IDisposable |
There was a problem hiding this comment.
There should be a separate file Logger.cs
| public class Logger : IDisposable | ||
| { | ||
| private static Logger? instance; | ||
| private readonly string logFilePath; |
There was a problem hiding this comment.
can you specify the reason because of which you made this as readOnly?
|
|
||
| public class Logger : IDisposable | ||
| { | ||
| private static Logger? instance; |
There was a problem hiding this comment.
Name of logger instance should be _logger or something more resonable. Question reads as "Include a private static field instance of type Logger" which means to create an instance of Logger not to name it as instance.
| public class Logger : IDisposable | ||
| { | ||
| private static Logger? instance; | ||
| private readonly string logFilePath; |
There was a problem hiding this comment.
this should also be named as _logFilePath
| { | ||
| private static Logger? instance; | ||
| private readonly string logFilePath; | ||
| private StreamWriter? logWriter; |
|
|
||
| private void Log(string message) | ||
| { | ||
| logWriter?.WriteLine($"{DateTime.Now}: {message}"); |
There was a problem hiding this comment.
where are you checking if the file exists or not?
|
|
||
| public static void Main(string[] args) | ||
| { | ||
| using var logger = Logger.Instance; |
There was a problem hiding this comment.
don't use var if you know the type of the instance.
| logWriter?.Flush(); | ||
| } | ||
|
|
||
| public void Dispose() |
There was a problem hiding this comment.
this function is called no where.. this should be called in the destructor of logger class