Exemplo n.º 1
0
        public static void Debug(this ILogger logger,
                                 string message,
                                 Exception exception = null,
                                 string traceId      = null,
                                 string userId       = null,
                                 [System.Runtime.CompilerServices.CallerMemberName]
                                 string memberName = "",
                                 [System.Runtime.CompilerServices.CallerFilePath]
                                 string sourceFilePath = "",
                                 [System.Runtime.CompilerServices.CallerLineNumber]
                                 int sourceLineNumber = 0,
                                 params string[] tags)
        {
            var logInfo = new CCloudLogInfo()
            {
                ClassFile  = Path.GetFileName(sourceFilePath),
                ThreadId   = Thread.CurrentThread.ManagedThreadId,
                ThreadName = Thread.CurrentThread.Name,
                LineNumber = sourceLineNumber,
                Message    = message,
                TraceId    = traceId,
                UserId     = userId,
                MemberName = memberName,
                Tags       = tags,
                LogLevel   = LogLevel.Debug
            };

            logger.Log(logInfo.LogLevel, eventId: EmptyEventId, logInfo, exception, Formatter);
        }
Exemplo n.º 2
0
        public static void Info(this ILogger logger,
                                string message,
                                Exception exception = null,
                                string traceId      = null,
                                string userId       = null,
                                [System.Runtime.CompilerServices.CallerMemberName]
                                string memberName = "",
                                [System.Runtime.CompilerServices.CallerFilePath]
                                string sourceFilePath = "",
                                [System.Runtime.CompilerServices.CallerLineNumber]
                                int sourceLineNumber = 0,
                                params string[] tags)
        {
            // 刚好在 Linux 下构建的在 Linux 下运行,而在 Windows 构建的库在 Windows 下执行。此时使用 GetFileNameWithoutExtension 能保持输入路径和解析相同
            // 假定在 Windows 下构建而在 Linux 下构建,只是让路径变长而已,我相信咱的日志系统炸不了…… 或者说,炸了再说
            // 炸了的解决方法是在 dotnet runtime\src\libraries\System.Private.CoreLib\src\System\IO\Path.cs 的 GetFileName 方法里面将 `PathInternal.IsDirectorySeparator(path[i])` 替换为实际需要的 \ 或 / 符号

            const LogLevel logLevel = LogLevel.Information;
            var            logInfo  = new CCloudLogInfo()
            {
                ClassFile  = Path.GetFileName(sourceFilePath),
                ThreadId   = Thread.CurrentThread.ManagedThreadId,
                ThreadName = Thread.CurrentThread.Name,
                LineNumber = sourceLineNumber,
                Message    = message,
                TraceId    = traceId,
                UserId     = userId,
                MemberName = memberName,
                Tags       = tags,
                LogLevel   = logLevel
            };

            logger.Log(logLevel, eventId: EmptyEventId, logInfo, exception, Formatter);
        }