Exemplo n.º 1
0
        /// <summary>
        /// Creates a new child scope.
        /// </summary>
        /// <param name="childName"> The name of the scope. </param>
        /// <param name="value">A value that should be logged as part of the creation.</param>
        /// <param name="member">The name of the method.</param>
        /// <param name="path">The path of the source file.</param>
        /// <returns>A new scope.</returns>
        public LogScope Child(string childName, object value = null, [CallerMemberName] string member = "", [CallerFilePath] string path = "")
        {
            var scope = new LogScope(childName, member, path, this, this.logMethod)
            {
                Level    = this.Level,
                Category = this.Category,
            };

            if (value != null)
            {
                scope.Log(LogCategories.Technical, LogLevel.Debug, "scope value: ", value);
            }

            return(scope);
        }
Exemplo n.º 2
0
        private LogScope(string scopeName, string member, string path, LogScope parent, Action <LogCategories, LogLevel, LogScope, string> logMethod)
        {
            this.scopeName = scopeName;
            this.logMethod = logMethod ?? LogMethod;

            var newId = LogScope.IdFactory(parent ?? this);

            this.Id = $"{parent?.Id}/{newId}";

            var replace = !string.IsNullOrEmpty(LogScope.BasePath) && !string.IsNullOrEmpty(path)
                ? path.Replace(LogScope.BasePath, string.Empty, StringComparison.OrdinalIgnoreCase)
                : path;

            var pat = replace?.Trim('\\').Trim('/');

            this.Log(LogCategories.Technical, LogLevel.Trace, $"Starting scope {scopeName} in member {member} of {pat}.");
        }