Search code examples
c#loggingstreamwriter

Creating log file with extension 'log'


I want to create a log file with extension 'log' but a simple text file is created (txt) but when I create a data file with extension 'dat' it works.

var ext = ".log";
using (StreamWriter sw = new StreamWriter(dir + @"\" + title + ext))
{
   sw.Write(rows);
   sw.Flush();
}

or

using (StreamWriter sw = File.CreateText(dir + @"\" + title + ext))
{}

I would like to show extension ".log" in file name. Could someone help me, please?


Solution

  • I do assume that your file is created correctly. You just do not see .log extension in explorer because of its default settings:

    enter image description here