服務響應我有一個WCF服務。我有這個操作記錄了服務中的任何請求。我在這裏遇到的問題是它將每個請求記錄在單獨的文件中。如何將所有日誌記錄在單個文件中,並將每個日誌與單行分開?如何登錄一個文件
我想記錄它在一個文件中的性能的原因。
public byte sendMessage(string strMsgId, string strMessage)
{
byte result = 1;
try
{
if (strMsgId == "02")
{
// Logging---------------------------------------------------------------------------------
// Build timestamp string
var currentDateTime = DateTime.Now;
string timeStampString = currentDateTime.ToString("yyyy-MM-dd hhmmssfff");
// Build filename for Inbound messages, concat timestamp and .txt extension.
string debugFileName = "C:\\Inboundmessage" + " " + timeStampString + ".txt";
var inboundMessageLog = new StreamWriter(debugFileName, false, System.Text.Encoding.Default);
// Write to the file:
inboundMessageLog.WriteLine(DateTime.Now);
inboundMessageLog.WriteLine("Time = {0}", currentDateTime.ToString("yyyy-MM-dd hh:mm:ss:fff tt"));
inboundMessageLog.WriteLine("{0}{1}{2}", "Inbound Message:", Environment.NewLine, strMessage.Substring(1016, 26));
inboundMessageLog.Close();
// -------------------------------------------------------------------------------------------
result = 0;
}
}
catch
{
//Failed
result = 1;
}
return result;
登錄到數據庫來代替。 ;) – zimdanen