Last active
June 11, 2018 12:24
-
-
Save skenderbeu/eea1a57a569de8ddfc2d55729cdbe425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.ServiceModel.Channels; | |
using System.Text; | |
using System.Xml; | |
namespace RoyalMail | |
{ | |
public class LogMessage | |
{ | |
protected string fileName; | |
public void WriteLog(ref Message message) | |
{ | |
try | |
{ | |
MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue); | |
message = buffer.CreateMessage(); | |
Message copyMessage = buffer.CreateMessage(); | |
using (StreamWriter sw = File.CreateText(fileName)) | |
{ | |
CreateMessage(copyMessage, sw); | |
if (copyMessage.IsEmpty) return; | |
sw.WriteLine(); | |
sw.WriteLine(copyMessage.ToString()); | |
} | |
} | |
catch | |
{ | |
// ignored | |
} | |
} | |
protected virtual void CreateMessage(Message message, StreamWriter sw) { } | |
protected string GetDateStamp() | |
{ | |
return string.Format("{0}{1}{2}T{3}{4}{5}_{6}", DateTime.Now.Year, DateTime.Now.Month, | |
DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, | |
DateTime.Now.Second, DateTime.Now.Millisecond); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment