0

I am currently using the Microsoft.Practices.EnterpriseLibrary.Logging but I can't find a way to control where the file is written to except through pre-runtime configuration.

I am looking at System.IO.Log, but it only seems to create a binary file that cannot be viewed by a simple text editor.

Is there a way to produce a flat text file with System.IO.Log? or Is there a way to control the location of the log file at runtime using Microsoft.Practices.EnterpriseLibrary.Logging

  • Can [this](https://stackoverflow.com/questions/30786387/enterprise-library-6-dynamically-change-log-file-name) help? – Peter Bons May 15 '20 at 13:50

1 Answers1

-1

I do not know if this helps but here goes.

public class Logger
{
    public void WriteToLog(string messageText)
    {
        // echo message to console
        Console.WriteLine(messageText);
        string strLogFile = "C:\\Users\\gandalf\\Documents\\Visual Studio 2000\\Projects\\fasterTest_Log.txt";
        string strLogText = messageText;

        // Create a writer and open the file:
        StreamWriter log;

        if (!File.Exists(strLogFile))
        {
            log = new StreamWriter(strLogFile);
        }
        else
        {
            log = File.AppendText(strLogFile);
        }

        // Write to the file:
        log.WriteLine(DateTime.Now + " : " + strLogText);

        // Close the stream:
        log.Close();
    }

}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Armygrad
  • 53
  • 5
  • Thanks. I doesn't use System.IO.Log, but I am thinking the logging library is overkill and my solution will be similar to your suggestion. – Kipp Woodard May 28 '20 at 13:06