示例#1
0
 public static void LogInfo(String info = "", String extraInfo = "")
 {
     LogText += $"{info}:\n{extraInfo}\n\n";
     try
     {
         InfoLogged?.Invoke(info, extraInfo);
     }
     catch
     {
     }
 }
示例#2
0
        public static void Info(string format, object o1 = null, object o2 = null, object o3 = null, object o4 = null, object o5 = null, object o6 = null, object o7 = null, object o8 = null, object o9 = null, object o10 = null)
        {
            if (string.IsNullOrEmpty(format))
            {
                return;
            }

            // no caller info in INFO
            string text = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " INFO] " +
                          string.Format(format, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10);

            // thread-safe 인 _writer 를 점유하고 있는 놈이 완전히 처리하기 전에 불리는 count 를 센다.
            _bufferCount++;

            // 새로 생기거나 날짜가 바뀌면 새로운 _streamWriter 를 할당한다.
            if (_fileName == null || !_fileName.StartsWith(DateTime.Now.ToString("yyyyMMdd")))
            {
                lock (_writerCreateLock)
                {
                    if (_writer != null)
                    {
                        _writer.Close();
                    }

                    System.Reflection.Assembly assembly = System.Reflection.Assembly.GetEntryAssembly();
                    if (assembly == null) // unmanaged code 등에서 불리면 null 이 된다.
                    {
                        assembly = System.Reflection.Assembly.GetCallingAssembly();
                    }

                    _fileName = DateTime.Now.ToString("yyyyMMdd") + "." + assembly.GetName().Name + ".txt";

                    _writer = TextWriter.Synchronized(new StreamWriter(Path.Combine(_logFolderPath, _fileName), true)); // thread-safe
                }
            }

            // 쓴다.
            if (Async)
            {
                _writer.WriteLineAsync(text);
            }
            else
            {
                _writer.WriteLine(text);
                _writer.Flush();
            }

            // 버퍼에 쌓여있는 양을 처리하고 나면 동일한 양의 로그가 또 쌓여있는 상황을 이상적인 _bufferSize 로 본다.
            if (_bufferCount > _bufferSize)
            {
                _bufferSize = Math.Min(_bufferSize + 1, int.MaxValue);
            }
            else
            {
                _bufferSize = Math.Max(_bufferSize - 1, 0);
            }

            if (_bufferCount >= _bufferSize)
            {
                Flush();
            }

            if (InfoOnConsole)
            {
                Console.WriteLine(text);
            }

            InfoLogged?.Invoke(null, new LoggedEventArgs(text));
        }
示例#3
0
 public static void Info(string message)
 {
     Instance?.Info(message);
     InfoLogged?.Invoke(null, new MessageLoggedEventArgs(message));
 }