コード例 #1
0
ファイル: FormattedLogObject.cs プロジェクト: vip32/Logging
        public override string ToString()
        {
            if (this.data == null)
            {
                return(string.Empty);
            }

            var logObject = default(LogObject);

            if (this.data is string stringData)
            {
                logObject = new LogObject
                {
                    Category = this.category,
                    LogLevel = logLevel,
                    Type     = LogObjectType.String,
                    Payload  = stringData,
                };
            }
            else
            {
                var isDataEnumerable = this.IsDataEnumerable(this.data);

                logObject = new LogObject
                {
                    Category = this.category,
                    LogLevel = logLevel,
                    Type     = isDataEnumerable ? LogObjectType.Table : LogObjectType.Object,
                    Payload  = data
                };
            }

            if (this.exception != null)
            {
                logObject.Exception = this.exception.ToString();
            }

#if !DESKTOP_BUILD
            return(Newtonsoft.Json.JsonConvert.SerializeObject(logObject));
#else
            return(JsonConvert.SerializeObject(logObject, new JsonSerializerSettings
            {
                Formatting = Formatting.Indented,
                Converters = new[] { new StringEnumConverter(true) }
            }));
#endif
        }
コード例 #2
0
        public override string ToString()
        {
            if (this.data == null)
            {
                return(string.Empty);
            }

            var logObject = default(LogObject);

            if (this.data is string stringData)
            {
                logObject = new LogObject
                {
                    Category = this.category,
                    LogLevel = logLevel,
                    Type     = LogObjectType.String,
                    Payload  = stringData,
                };
            }
            else
            {
                var isDataEnumerable = this.IsDataEnumerable(this.data);

                logObject = new LogObject
                {
                    Category = this.category,
                    LogLevel = logLevel,
                    Type     = isDataEnumerable ? LogObjectType.Table : LogObjectType.Object,
                    Payload  = data
                };
            }

            if (this.exception != null)
            {
                logObject.Exception = this.exception.ToString();
            }

            return(JsonSerializer.Serialize(logObject, jsonOptions));
        }