Пример #1
0
        /// <summary>
        /// Log method entry
        /// </summary>
        /// <param name="methodName">The name of the method being logged</param>
        /// <param name="options">The log options</param>
        /// <param name="source">The TraceSource that events are written to</param>
        /// <returns>A disposable object or none if logging is disabled</returns>
        public static IDisposable Log(string methodName,
                                      LogOptions options)
        {
            IDisposable logger = null;

            // Check if ExecutionTime logging is requested, and if so log if Verbose
            // logging (or greater) is chosen
            bool shouldCreate = (options & LogOptions.ExecutionTime) == LogOptions.ExecutionTime;

            // If not logging ExecutionTime, see if ActivityTracing is on, and if so
            // log only if Entry or Exit tracing is requested
            if (!shouldCreate)
            {
                shouldCreate = (((options & LogOptions.Entry) == LogOptions.Entry) | ((options & LogOptions.Exit) == LogOptions.Exit));
            }

            // Check if we actually need to log anything
            if (shouldCreate)
            {
                logger = new MethodLogger(methodName, options);
            }

            // Will return null if no method logger was needed - which will
            // effectively be ignored by a using statement.
            return(logger);
        }
Пример #2
0
        /// <summary>
        /// Log method entry 
        /// </summary>
        /// <param name="methodName">The name of the method being logged</param>
        /// <param name="options">The log options</param>
        /// <param name="source">The TraceSource that events are written to</param>
        /// <returns>A disposable object or none if logging is disabled</returns>
        public static IDisposable Log(string methodName,
                                      LogOptions options)
        {
            IDisposable logger = null;

            // Check if ExecutionTime logging is requested, and if so log if Verbose
            // logging (or greater) is chosen
            bool shouldCreate = (options & LogOptions.ExecutionTime) == LogOptions.ExecutionTime;

            // If not logging ExecutionTime, see if ActivityTracing is on, and if so
            // log only if Entry or Exit tracing is requested
            if (!shouldCreate)
                shouldCreate = (((options & LogOptions.Entry) == LogOptions.Entry) | ((options & LogOptions.Exit) == LogOptions.Exit));

            // Check if we actually need to log anything
            if (shouldCreate)
                logger = new MethodLogger(methodName, options);

            // Will return null if no method logger was needed - which will
            // effectively be ignored by a using statement.
            return logger;
        }