Example #1
0
    /// <summary>
    /// Writes 10.000 log messages and outputs the required time.
    /// </summary>
    private static void LogMessages()
    {
        DateTime        startTime = DateTime.UtcNow;
        List <TimeSpan> durations = new List <TimeSpan>();

        for (int x = 0; x < 10; x++)
        {
            for (int i = 0; i < 100; i++)
            {
                CustomLogger.Info("Application started.");
//                Debug.Log("This is a normal Unity Debug.Log message for comparison.");
                CustomLogger.Info(
                    "Welcome to the NLog Sample Project. Our log is being written to Unitys persistentDataPath.");
                CustomLogger.Info(
                    "To find it, read here: https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html");
                CustomLogger.Warn("No game content found, this is likely just a sample project.");


                // Logging Exceptions
                try
                {
                    throw new InvalidOperationException("This is a manually invoked exception");
                }
                catch (Exception ex)
                {
                    CustomLogger.Error(ex, "Hello this is a Message about the exception");
                }
            }

            durations.Add(DateTime.UtcNow - startTime);
        }

        CustomLogger.Error("End of game reached. Please restart.");
        Debug.Log("Duration: " + durations.Average(span => span.TotalMilliseconds) +
                  "ms. Most of this time goes into the Unity console. Writing to the file is super quick.");
    }
Example #2
0
        /// <summary>
        /// 为keyword做盘古分词
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        private static string AnalyzerKeyword(string keyword, string fieldName)
        {
            StringBuilder  queryStringBuilder = new StringBuilder();
            ILuceneAnalyze analyzer           = new LuceneAnalyze();
            List <string>  words = analyzer.AnalyzerKey(keyword, fieldName);

            if (words.Count == 1)
            {
                queryStringBuilder.AppendFormat("{0}:{1}* ", fieldName, words[0]);
            }
            else
            {
                StringBuilder fieldQueryStringBuilder = new StringBuilder();
                foreach (string word in words)
                {
                    queryStringBuilder.AppendFormat("{0}:{1} ", fieldName, word);
                }
            }
            string result = queryStringBuilder.ToString().TrimEnd();

            m_logger.Info(string.Format("AnalyzerKeyword 将 keyword={0}转换为{1}", keyword, result));

            return(result);
        }