Пример #1
0
        public static void DefaultSetDestinationsProc(LogServerReceivedData data, LogServerOptions options)
        {
            FileSystem  fs       = options.DestFileSystem;
            PathParser  parser   = fs.PathParser;
            string      root     = options.DestRootDirName;
            LogPriority priority = data.JsonData !.Priority._ParseEnum(LogPriority.None);
            LogJsonData d        = data.JsonData;

            if (d.Kind._IsSamei(LogKind.Default))
            {
                if (priority >= LogPriority.Debug)
                {
                    Add($"{d.AppName}/{d.MachineName}/Debug");
                }

                if (priority >= LogPriority.Info)
                {
                    Add($"{d.AppName}/{d.MachineName}/Info");
                }

                if (priority >= LogPriority.Error)
                {
                    Add($"{d.AppName}/{d.MachineName}/Error");
                }
            }
            else
            {
                Add($"{d.AppName}/{d.MachineName}/{d.Kind}");
            }

            void Add(string filename)
            {
                data.AddDestinationFileName(parser.NormalizeDirectorySeparator(parser.Combine(root, filename + ".log")));
            }
        }
Пример #2
0
        public void WriteRecordToBuffer(LogInfoOptions opt, MemoryBuffer <byte> b)
        {
            if (opt.WriteAsJsonFormat && Dbg.IsJsonSupported)
            {
                // JSON text
                LogJsonData jc = new LogJsonData();

                if (opt.WithTimeStamp)
                {
                    jc.TimeStamp = this.TimeStamp;
                }

                if (opt.WithGuid)
                {
                    jc.Guid = this.Guid;
                }

                if (opt.WithMachineName)
                {
                    jc.MachineName = opt.MachineName;
                }

                if (opt.WithAppName)
                {
                    jc.AppName = opt.AppName;
                }

                if (opt.WithKind)
                {
                    jc.Kind = opt.Kind;
                }

                if (opt.WithPriority)
                {
                    jc.Priority = this.Priority.ToString();
                }

                if (opt.WithTag)
                {
                    jc.Tag = this.Tag._FilledOrDefault(LogTag.None);
                }

                if (opt.WithTypeName)
                {
                    jc.TypeName = this.Data?.GetType().Name ?? "null";
                }

                jc.Data = this.Data;

                string jsonText = jc._GetObjectDump(jsonIfPossible: true);

                b.Write(jsonText._GetBytes_UTF8());
                b.Write(CrLfByte);
            }
            else
            {
                // Normal text
                StringBuilder sb = new StringBuilder();

                // Timestamp
                if (opt.WithTimeStamp)
                {
                    sb.Append(this.TimeStamp._ToDtStr(true, DtStrOption.All, false));
                    sb.Append(" ");
                }

                // Additional strings
                List <string?> additionalList = new List <string?>();

                if (opt.WithGuid)
                {
                    additionalList.Add(this.Guid);
                }

                if (opt.WithMachineName)
                {
                    additionalList.Add(opt.MachineName);
                }

                if (opt.WithAppName)
                {
                    additionalList.Add(opt.AppName);
                }

                if (opt.WithKind)
                {
                    additionalList.Add(opt.Kind);
                }

                if (opt.WithPriority)
                {
                    additionalList.Add(this.Priority.ToString());
                }

                if (opt.WithTag)
                {
                    additionalList.Add(this.Tag._FilledOrDefault(LogTag.None));
                }

                if (opt.WithTypeName)
                {
                    additionalList.Add(this.Data?.GetType().Name ?? "null");
                }

                string additionalStr = Str.CombineStringArray(" ", additionalList.ToArray());
                if (additionalStr._IsFilled())
                {
                    sb.Append("[");
                    sb.Append(additionalStr);
                    sb.Append("] ");
                }

                // Log text
                string logText = GetMultilineText(GetTextFromData(this.Data, opt), opt);
                sb.Append(logText);
                sb.Append("\r\n");

                b.Write(sb.ToString()._GetBytes_UTF8());
            }
        }