// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Configuration; using System.IO; using System.Web.Services.Protocols; namespace E { public class LogStream : Stream { private Stream real; private Stream log; public LogStream(Stream real, Stream log) { this.real = real; this.log = log; } public override bool CanRead { get { return true; } } public override bool CanSeek { get { return false; } } public override bool CanWrite { get { return true; } } public override long Length { get { return real.Length; } } public override long Position { get { return real.Position; } set { throw new NotSupportedException(); } } public override int Read(byte[] buffer, int offset, int count) { int n = real.Read(buffer, offset, count); log.Write(buffer, offset, n); log.Flush(); return n; } public override long Seek(long offset, SeekOrigin direction) { throw new NotSupportedException(); } public override void SetLength(long length) { throw new NotSupportedException(); } public override void Close() { real.Close(); } public override void Flush() { real.Flush(); } public override void Write(byte[] buffer, int offset, int count) { real.Write(buffer, offset, count); log.Write(buffer, offset, count); log.Flush(); } } public class LogExtension : SoapExtension { public override void ProcessMessage(SoapMessage msg) { } public override void Initialize(object init) { } public override object GetInitializer(Type typ) { return null; } public override object GetInitializer(LogicalMethodInfo lmi, SoapExtensionAttribute soapextatr) { return null; } public override Stream ChainStream(Stream stm) { return new LogStream(stm, new FileStream(ConfigurationManager.AppSettings["log.file"], FileMode.Append, FileAccess.Write, FileShare.Write)); } } }