2009-11-11 36 views

回答

1

從內存中,你需要創建一個自定義格式,類似於this link東西。

0

有關執行字符串在您的郵件替換替代空間爲換行符是什麼?

配置您的格式化模板是這樣的:

<formatters> 
    <add template="{timestamp}: {category}: {severity}: {message}" 
    type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null" 
    name="My Text Formatter" /> 
</formatters> 


然後在你的代碼替換新線與空間(這可以在一個集中的輔助方法來完成):

string message = @"This is 
the message 
to log."; 

message.Replace(Environment.NewLine, " "); 


這應該會導致一個日誌文件看起來像:

11/11/2009 2:52:01 PM: My Category Event: Information: This is the message to log. 
11/11/2009 2:53:47 PM: My Category Event: Information: More test to log to the file.