Skip to content

Homework 3#3

Open
prashant1shukla wants to merge 3 commits intomainfrom
Homework-3
Open

Homework 3#3
prashant1shukla wants to merge 3 commits intomainfrom
Homework-3

Conversation

@prashant1shukla
Copy link
Owner

image

using System;
using System.IO;

public class Logger : IDisposable

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a separate file Logger.cs

public class Logger : IDisposable
{
private static Logger? instance;
private readonly string logFilePath;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you specify the reason because of which you made this as readOnly?


public class Logger : IDisposable
{
private static Logger? instance;
Copy link

@sanchit203 sanchit203 May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also be named as _logFilePath

{
private static Logger? instance;
private readonly string logFilePath;
private StreamWriter? logWriter;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here... _ is missing


private void Log(string message)
{
logWriter?.WriteLine($"{DateTime.Now}: {message}");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are you checking if the file exists or not?


public static void Main(string[] args)
{
using var logger = Logger.Instance;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use var if you know the type of the instance.

logWriter?.Flush();
}

public void Dispose()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is called no where.. this should be called in the destructor of logger class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants