Exemple #1
0
        /// <summary>
        /// Writes a Log message
        /// </summary>
        /// <param name="args">
        ///     <para>A collection of Log data</para>
        ///     <para>Eg: new KissLog.Args("value1", 100)</para>
        /// </param>
        public static void Trace(this IKLogger logger, Args args, JsonSerializeOptions options        = null,
                                 [System.Runtime.CompilerServices.CallerMemberName] string memberName = null,
                                 [System.Runtime.CompilerServices.CallerLineNumber] int lineNumber    = 0,
                                 [System.Runtime.CompilerServices.CallerFilePath] string memberType   = null)
        {
            if (logger == null)
            {
                return;
            }

            logger.Log(LogLevel.Trace, args, options, memberName, lineNumber, memberType);
        }
Exemple #2
0
        /// <summary>
        /// Writes a Log message
        /// </summary>
        /// <param name="json">Log data</param>
        public static void Critical(this IKLogger logger, object json, JsonSerializeOptions options      = null,
                                    [System.Runtime.CompilerServices.CallerMemberName] string memberName = null,
                                    [System.Runtime.CompilerServices.CallerLineNumber] int lineNumber    = 0,
                                    [System.Runtime.CompilerServices.CallerFilePath] string memberType   = null)
        {
            if (logger == null)
            {
                return;
            }

            logger.Log(LogLevel.Critical, json, options, memberName, lineNumber, memberType);
        }
Exemple #3
0
        /// <summary>
        /// Serializes an object to JSON
        /// </summary>
        /// <param name="Object">Object to be serialized</param>
        /// <param name="Options">Options for formatting the object</param>
        /// <returns>JSON representation of the object</returns>
        public static string Serialize(object Object, JsonSerializeOptions Options)
        {
            fastJSON.JSONParameters Params = new fastJSON.JSONParameters();
            Params.EnableAnonymousTypes = true;

            string Text = fastJSON.JSON.Instance.ToJSON(Object, Params);

            if ((Options & JsonSerializeOptions.PrettyPrint) != 0)
            {
                Text = Format(Text);
            }
            return(Text);
        }
        /// <summary>
        /// Returns whether specified json data is safe, according to checks filtered with options.
        /// </summary>
        public static bool IsJsonSafe(JsonData data, JsonSerializeOptions options)
        {
            // No checks required.
            if (options.IgnoreSafetyChecks)
            {
                return(true);
            }

            // Circular reference check.
            if (!options.IgnoreCircularReference && IsCircularReference(data))
            {
                RenLog.Log(LogLevel.Error, "JsonSerializeSafety.IsJsonSafe - Failed to pass circular reference check.");
                return(false);
            }

            // Everything looks good
            return(true);
        }
        public void IExcludedInterfaceSerializer_RegistersSerializeAsToString_InvokesToString()
        {
            var testObject = BuildSampleObject();

            var sb      = new StringBuilder();
            var options = new JsonSerializeOptions();

            var logFactory = new LogFactory();

            logFactory.Setup().SetupSerialization(s => s.RegisterObjectTransformation <IExcludedInterface>(o => o.ToString()));

            var jsonSerializer = new DefaultJsonSerializer(logFactory.ServiceRepository);

            jsonSerializer.SerializeObject(testObject, sb, options);
            const string expectedValue =
                @"{""S"":""sample"", ""Excluded"":""Skipped"", ""Included"":{""IncludedString"":""serialized""}}";

            Assert.Equal(expectedValue, sb.ToString());
        }
        public void IExcludedInterfaceSerializer_RegistersSerializeAsToString_InvokesToString()
        {
            try
            {
                var testObject = BuildSampleObject();

                var sb      = new StringBuilder();
                var options = new JsonSerializeOptions();

                LogManager.Setup().SetupSerialization(s => s.RegisterObjectTransformation <IExcludedInterface>(o => o.ToString()));

                var jsonSerializer = new DefaultJsonSerializer();
                jsonSerializer.SerializeObject(testObject, sb, options);
                const string expectedValue =
                    @"{""S"":""sample"", ""Excluded"":""Skipped"", ""Included"":{""IncludedString"":""serialized""}}";
                Assert.Equal(expectedValue, sb.ToString());
            }
            finally
            {
                NLog.Config.ConfigurationItemFactory.Default.ObjectTypeTransformer = null;
            }
        }
Exemple #7
0
        public void Log(LogLevel logLevel, Args args, JsonSerializeOptions options = null, string memberName = null, int lineNumber = 0, string memberType = null)
        {
            if (args == null)
            {
                return;
            }

            List <string> values = new List <string>();

            foreach (var arg in args.GetArgs())
            {
                string message = null;

                if (arg is string stringArg)
                {
                    message = stringArg;
                }
                else if (arg is Exception exceptionArg)
                {
                    var formatter = new ExceptionFormatter();
                    message = formatter.Format(exceptionArg, this);
                }
                else
                {
                    message = KissLogConfiguration.JsonSerializer.Serialize(arg, options);
                }

                if (string.IsNullOrEmpty(message))
                {
                    continue;
                }

                values.Add(message);
            }

            string value = string.Join(Environment.NewLine, values);

            Log(logLevel, value, memberName, lineNumber, memberType);
        }
Exemple #8
0
 private string SerializeObjectWithOptions(object o, JsonSerializeOptions options)
 {
     return(_serializer.SerializeObject(o, options)); //calls IJsonSerializer
 }
 public InternalPersistence(CommonOptions yuzuCommonOptions, JsonSerializeOptions yuzuJsonOptions)
     : base(yuzuCommonOptions, yuzuJsonOptions)
 {
 }
Exemple #10
0
 public Persistence(CommonOptions yuzuCommonOptions, JsonSerializeOptions yuzuJsonOptions) : this()
 {
     YuzuCommonOptions = yuzuCommonOptions;
     YuzuJsonOptions   = yuzuJsonOptions ?? defaultYuzuJsonOptions;
 }
Exemple #11
0
        public void Log(LogLevel logLevel, object json, JsonSerializeOptions options = null, string memberName = null, int lineNumber = 0, string memberType = null)
        {
            string message = KissLogConfiguration.JsonSerializer.Serialize(json, options);

            Log(logLevel, message, memberName, lineNumber, memberType);
        }
Exemple #12
0
 public Yuzu(CommonOptions yuzuCommonOptions, JsonSerializeOptions yuzuJsonOptions) : this()
 {
     YuzuCommonOptions = yuzuCommonOptions;
     YuzuJsonOptions   = yuzuJsonOptions;
 }