是否可以使用 System.IO.Log 生成简单的纯文本文件?



我目前正在使用 Microsoft.Practices.EnterpriseLibrary.Logging,但除了通过运行时前配置之外,我找不到控制文件写入位置的方法。

我正在查看System.IO.Log,但它似乎只创建了一个无法通过简单文本编辑器查看的二进制文件。

有没有办法使用 System.IO.Log 生成纯文本文件? 或 有没有办法使用 Microsoft.Practices.EnterpriseLibrary.Logging 控制日志文件在运行时的位置

我不知道这是否有帮助,但在这里。

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();
}
}

最新更新