Skip to main content
added 2 characters in body
Source Link
Flater
  • 5.7k
  • 19
  • 23
added 580 characters in body
Source Link
Flater
  • 5.7k
  • 19
  • 23

Addendum

Piedar made a really interesting remark in the comments. Apparently, string + string concatenation is now converted to String.Concat by the compiler. This effectively negates the issue I'm pointing at.

However, I still urge you to not do + concatenation on big string anyway, from a readability perspective. value + " seconds" is readably enough, but you're pasting a lot of different things together and the code starts looking bulky and ugly.
However, this is a style (and, in extreme cases, readability) argument, not a technical one.

Addendum

Piedar made a really interesting remark in the comments. Apparently, string + string concatenation is now converted to String.Concat by the compiler. This effectively negates the issue I'm pointing at.

However, I still urge you to not do + concatenation on big string anyway, from a readability perspective. value + " seconds" is readably enough, but you're pasting a lot of different things together and the code starts looking bulky and ugly.
However, this is a style (and, in extreme cases, readability) argument, not a technical one.

deleted 14 characters in body
Source Link
Flater
  • 5.7k
  • 19
  • 23
private void WriteMessageToFile(string filepath, string message)
{
    StreamWriter sw = null;
    try
    {
        sw = new StreamWriter("some file path"filepath, true);
        sw.WriteLine("some string"message);
        sw.Flush();
        sw.Close();
    catch (Exception ex)
    {
        throw ex;
    }
}

Caveat
However, writing your own logging framework from scratch (with no knowledge of other frameworkexisting frameworks) can be rewarding in and of itself as a training exercise.

Based on your code, I surmise that you are a beginner, at least to creating reusable libraries. So if writing this library benefits you for training purposes, don't let my review stop you.
But

But if your only goal is to create a functionally usable tool, then I do suggest first looking for existing solutions, either to already solve your problem or even just to get some inspiration/ideas.

private void WriteMessageToFile(string filepath, string message)
{
    StreamWriter sw = null;
    try
    {
        sw = new StreamWriter("some file path", true);
        sw.WriteLine("some string");
        sw.Flush();
        sw.Close();
    catch (Exception ex)
    {
        throw ex;
    }
}

Caveat
However, writing your own logging framework from scratch (with no knowledge of other framework) can be rewarding in and of itself as a training exercise.

Based on your code, I surmise that you are a beginner, at least to creating reusable libraries. So if writing this library benefits you for training purposes, don't let my review stop you.
But if your only goal is to create a functionally usable tool, then I do suggest first looking for existing solutions, either to already solve your problem or even just to get some inspiration/ideas.

private void WriteMessageToFile(string filepath, string message)
{
    StreamWriter sw = null;
    try
    {
        sw = new StreamWriter(filepath, true);
        sw.WriteLine(message);
        sw.Flush();
        sw.Close();
    catch (Exception ex)
    {
        throw ex;
    }
}

Caveat
However, writing your own logging framework from scratch (with no knowledge of existing frameworks) can be rewarding in and of itself as a training exercise.

Based on your code, I surmise that you are a beginner, at least to creating reusable libraries. So if writing this library benefits you for training purposes, don't let my review stop you.

But if your only goal is to create a functionally usable tool, then I do suggest first looking for existing solutions, either to already solve your problem or even just to get some inspiration/ideas.

Source Link
Flater
  • 5.7k
  • 19
  • 23
Loading