Exemplo n.º 1
0
        public static void FlushToFile(this MemoryLogger logger, string filePath, bool clearAfterFlush = false)
        {
            var logs = logger.Logs.ToArray();

            if (logs.Length > 0)
            {
                if (clearAfterFlush)
                {
                    logger.Logs.Clear();
                }
                var sb = new StringBuilder();
                foreach (var log in logs)
                {
                    sb.AppendLine($"{log.CreateAt.AsFormatDefault()} {log.Message}");
                }
                var content = sb.ToString();
                MakeSureDirExist(filePath);
                File.WriteAllText(filePath, content, Encoding.UTF8);
            }
        }