public Task <IValueProvider> BindAsync(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            TraceWriter trace = context.Trace;

            // If logger functionality is enabled, wrap an ILogger
            if (_loggerFactory != null)
            {
                ILogger logger = _loggerFactory.CreateLogger(LogCategories.Function);
                trace = new CompositeTraceWriter(new[] { trace, new LoggerTraceWriter(context.Trace.Level, logger) }, null, context.Trace.Level);
            }

            object tracer = null;

            if (_parameter.ParameterType == typeof(TraceWriter))
            {
                tracer = trace;
            }
            else
            {
                // bind to an adapter
                tracer = TextWriterTraceAdapter.Synchronized(trace);
            }

            return(BindAsync(tracer, context.ValueContext));
        }
Example #2
0
            public Task SetValueAsync(object value, CancellationToken cancellationToken)
            {
                TextWriterTraceAdapter traceAdapter = value as TextWriterTraceAdapter;

                if (traceAdapter != null)
                {
                    traceAdapter.Flush();
                }
                return(Task.FromResult(0));
            }
        public Task <IValueProvider> BindAsync(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ILogger     logger = _loggerFactory.CreateLogger(LogCategories.CreateFunctionUserCategory(context.ValueContext.FunctionContext.MethodName));
            TraceWriter trace  = new LoggerTraceWriter(logger);

            object tracer = trace;

            if (_parameter.ParameterType == typeof(TextWriter))
            {
                // bind to an adapter
                tracer = TextWriterTraceAdapter.Synchronized(trace);
            }

            return(BindAsync(tracer, context.ValueContext));
        }
        public Task<IValueProvider> BindAsync(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            object tracer = null;
            if (_parameter.ParameterType == typeof(TraceWriter))
            {
                // bind directly to the context TraceWriter
                tracer = context.Trace;
            }
            else
            {
                // bind to an adapter
                tracer = new TextWriterTraceAdapter(context.Trace);
            }

            return BindAsync(tracer, context.ValueContext);
        }
Example #5
0
        public Task <IValueProvider> BindAsync(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            object tracer = null;

            if (_parameter.ParameterType == typeof(TraceWriter))
            {
                // bind directly to the context TraceWriter
                tracer = context.Trace;
            }
            else
            {
                // bind to an adapter
                tracer = new TextWriterTraceAdapter(context.Trace);
            }

            return(BindAsync(tracer, context.ValueContext));
        }
 public TextWriterTraceAdapterTests()
 {
     _mockTraceWriter = new Mock<TraceWriter>(MockBehavior.Strict, TraceLevel.Verbose);
     _adapter = new TextWriterTraceAdapter(_mockTraceWriter.Object);
 }