public static IAdapterNativeLibraryDouble AddDiagnostics(ParametersDiagnosticsNative diagnostics, IAdapterNativeLibraryDouble engine, out Stream stream, bool isServer)
            {
                Contract.Requires(diagnostics != null, "diagnostics != null");
                Contract.Requires(engine != null, "engine != null");

                stream = null;

                if (diagnostics.To == WriteTo.None)
                    return engine;

                var log = diagnostics.Log;

                if (isServer && !diagnostics.LogServer)
                    log = null;

                if (log != null)
                {
                    try
                    {
                        if (!Path.IsPathRooted(log.FullName))
                            throw new Exception("Filename NOT rooted.");

                        if (isServer)
                        {
                            // Adapt from Client path

                            var n = log.FullName.Length - log.Extension.Length;
                            var s = log.FullName.Insert(n, "_Server");

                            log = new FileInfo(s);
                        }

                        if (File.Exists(log.FullName))
                            log.Delete();

                        stream = new BufferedStream(log.OpenWrite(), 20000);
                    }
                    catch (System.Exception e)
                    {
                        throw new Exception("Invalid Log fileName: " + log.FullName, e);
                    }
                }

                var intercepts = new List<IIntercept>();

                if (diagnostics.IncludeStatistics)
                    intercepts.Add(new InterceptCallReturnValues(diagnostics));

                if (diagnostics.IncludeCalls)
                    intercepts.Add(new InterceptCallArguments(diagnostics));

                if (diagnostics.IncludeTimings)
                    intercepts.Add(new InterceptCallTimer(diagnostics));

                if (stream != null)
                    foreach (var i in intercepts)
                        i.Streams.Add(stream);

                return new InterceptionAdapterNativeLibraryDouble(engine, intercepts, true);
            }
        public InterceptionAdapterNativeLibraryDouble(
            IAdapterNativeLibraryDouble engine, IEnumerable<IIntercept> intercepts, bool active)
            : base(intercepts, active)
        {
            Contract.Requires(engine != null, "engine != null");

            _engine = engine;
        }