예제 #1
0
        private static void TraceLine(string message = null, bool justTracer2 = false)
        {
            if (GetTraceLineInfo == null)
            {
                return;
            }

            var traceLineInfo = GetTraceLineInfo();

            if (!justTracer2)
            {
                Tracer1?.Trace(message, traceLineInfo.Extent, traceLineInfo.ScriptBlock, traceLineInfo.Level);
            }
            Tracer2?.Trace(message, traceLineInfo.Extent, traceLineInfo.ScriptBlock, traceLineInfo.Level);
        }
예제 #2
0
        /// <summary>
        /// Add a tracer to already setup session (to slot2). A tracer must implement ITracer or have a method `void Trace(string message, IScriptExtent extent, ScriptBlock scriptBlock, int level)`.
        /// </summary>
        /// <param name="tracer"></param>
        public static void Register(object tracer)
        {
            if (tracer is null)
            {
                throw new ArgumentNullException(nameof(tracer));
            }

            if (!HasTracer(Tracer1))
            {
                throw new InvalidOperationException($"Tracer1 is null. If you want to activate tracing call {nameof(Patch)}.");
            }

            if (HasDifferentTracer(Tracer2, tracer))
            {
                throw new InvalidOperationException($"Tracer2 already has tracer {Tracer2.GetType().Name}, and you are registering {tracer.GetType().Name}.");
            }

            Tracer2 = tracer is ITracer t ? t : new ExternalTracerAdapter(tracer);

            TraceLine(justTracer2: true);
        }