Skip to content

Instantly share code, notes, and snippets.

@skenderbeu

skenderbeu/LogMessage.cs

Last active Jun 11, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.