// 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.IO; using System.Text; public class RequestLogger : Stream { private Stream real; private StreamWriter log; public RequestLogger(Stream real, StreamWriter 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 false; } } 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(Encoding.UTF8.GetString(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) { throw new NotSupportedException(); } }