Esempio n. 1
0
        internal static void LogLongRequest(this ILogger logger, LogSource logSource, object metricContext)
        {
            try
            {
                if (logger == null)
                {
                    Console.WriteLine($"Логгер не инициализирован, stackTrace: {Environment.NewLine}{Environment.StackTrace}");
                    return;
                }

                if (metricContext == null)
                {
                    return;
                }

                var json = JsonConvert.SerializeObject(metricContext);

                var eventInfo = new LogEventInfo(LogLevel.Warn, logger.Name, "Long request WARN.")
                {
                    Properties =
                    {
                        new KeyValuePair <object, object>("metricSource", logSource.ToString()),
                        new KeyValuePair <object, object>("metricString", json),
                    }
                };
                logger.Log(eventInfo);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occured in Logger");
                Console.WriteLine(e);
            }
        }
Esempio n. 2
0
        public static void LogWarning(LogSource source, string message)
        {
            EventLog eventLog = new EventLog();

            eventLog.Source = source.ToString();
            eventLog.WriteEntry(message, EventLogEntryType.Warning);
        }
Esempio n. 3
0
        static public void LogInformation(LogSource source, string message)
        {
            EventLog eventLog = new EventLog();

            eventLog.Source = source.ToString();
            eventLog.WriteEntry(message, EventLogEntryType.Information);
        }
Esempio n. 4
0
        static public void LogError(LogSource source, string message)
        {
            EventLog eventLog = new EventLog();

            eventLog.Source = source.ToString();
            eventLog.WriteEntry(message, EventLogEntryType.Error);
        }
Esempio n. 5
0
        public LogMessage(LogLevel level, LogSource source, string message, string time)
        {
            this.Level   = level;
            this.Source  = source;
            this.message = message;
            this.time    = time;

            this.formattedMessage = string.Format("[{0}]: {2}", time, Source.ToString().ToUpper(), message);
        }
Esempio n. 6
0
        internal static void Write(LogSource Source, Exception Ex)
        {
            if (Ex == null || !EnableLogging) return;
            if (Ex.InnerException != null) Ex = Ex.InnerException;

            try
            {
                if (!Directory.Exists(ApplicationSettings.DataPath + "log\\"))
                    Directory.CreateDirectory(ApplicationSettings.DataPath + "log\\");

                LogFilePath = ApplicationSettings.DataPath + "log\\LOG." + DateTime.Today.ToString("yyyy-MM-dd") + ".EXCEPTION";

                LogStream = new FileStream(LogFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                Log = new StreamWriter(LogStream, Encoding.UTF8);

                StringBuilder SB = new StringBuilder();

                if (LogStream.Length < 21)
                    SB.AppendLine("<ERRORLOG>");
                else
                    LogStream.Position = LogStream.Length - 13;

                SB.AppendLine("  <LOG TIME=\"{0}\" SOURCE=\"{1}\">");
                SB.AppendLine("    <EXCEPTION>{2}</EXCEPTION>");
                SB.AppendLine("    <MESSAGE>{3}</MESSAGE>");
                SB.AppendLine("    <SOURCE>{4}</SOURCE>");
                SB.AppendLine("    <STACK>{5}</STACK>");
                SB.AppendLine("    <TARGETSITE>{6}</TARGETSITE>");
                SB.AppendLine("  </LOG>");

                SB.AppendLine("</ERRORLOG>"); // End the xml file

                Log.Write(
                    string.Format(SB.ToString(),
                    DateTime.Now.ToString("HH:mm:ss"),
                    Source.ToString(),
                    Ex.ToString(),
                    Ex.Message,
                    Ex.Source,
                    Ex.StackTrace,
                    Ex.TargetSite.Name));

                SB = null;
            }
            catch (Exception Exn)
            { }
            finally
            {
                if (Log != null) Log.Close(); Log = null;
                if (LogStream != null) LogStream.Close(); LogStream = null;
            }
        }
Esempio n. 7
0
File: L.cs Progetto: cjd0112/Comms
        public static void Trace(String str)
        {
            if (ExceptionOnly)
            {
                return;
            }

            WriteAsync($"{DateTime.UtcNow}\t{AsLogInfo.Info}\t{DefaultLogSource}\t{str}\r\n");

            if (_externalLogger != null)
            {
                _externalLogger.Log(new AsLogEntry(AsLogInfo.Info, DateTime.UtcNow, DefaultLogSource.ToString(), str));
            }
        }
Esempio n. 8
0
        protected override void AttachViewModel(object viewModel)
        {
            base.AttachViewModel(viewModel);

            var vm = viewModel as HistoryViewModel;

            if (vm != null)
            {
                LogSource = vm.LogSource as PathLogSource;
                if (LogSource != null)
                {
                    Text = Resources.StrHistory + ": " + LogSource.ToString();
                }
                else
                {
                    Text = Resources.StrHistory;
                }
            }
        }
Esempio n. 9
0
        public static void LogToConsole(string message, LogSource logSource = LogSource.Info)
        {
            string source = $"[{logSource.ToString()}]";

            //Set color
            switch (logSource)
            {
            case LogSource.Auth:
                System.Console.ForegroundColor = ConsoleColor.Cyan;
                break;

            case LogSource.GameServer:
                System.Console.ForegroundColor = ConsoleColor.Green;
                break;

            default:
                System.Console.ForegroundColor = ConsoleColor.Yellow;
                break;
            }

            Console.WriteLine($"{FormattedTimeStamp()}{source} - {message}");
        }
Esempio n. 10
0
		static public void LogInformation(LogSource source, string message)
		{
			EventLog eventLog = new EventLog();
			eventLog.Source = source.ToString();
			eventLog.WriteEntry(message, EventLogEntryType.Information);
		}
Esempio n. 11
0
		static public void LogError(LogSource source, string message)
		{
			EventLog eventLog = new EventLog();
			eventLog.Source = source.ToString();
			eventLog.WriteEntry(message, EventLogEntryType.Error);
		}
Esempio n. 12
0
        internal static void Write(LogSource Source, Exception Ex)
        {
            if (Ex == null || !EnableLogging)
            {
                return;
            }
            if (Ex.InnerException != null)
            {
                Ex = Ex.InnerException;
            }

            try
            {
                if (!Directory.Exists(ApplicationSettings.DataPath + "Logs\\"))
                {
                    Directory.CreateDirectory(ApplicationSettings.DataPath + "Logs\\");
                }

                LogFilePath = ApplicationSettings.DataPath + "Logs\\LOG." + DateTime.Today.ToString("yyyy-MM-dd") + ".EXCEPTION";

                LogStream = new FileStream(LogFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                Log       = new StreamWriter(LogStream, Encoding.UTF8);

                StringBuilder SB = new StringBuilder();

                if (LogStream.Length < 21)
                {
                    SB.AppendLine("<ERRORLOG>");
                }
                else
                {
                    LogStream.Position = LogStream.Length - 13;
                }

                SB.AppendLine("  <LOG TIME=\"{0}\" SOURCE=\"{1}\">");
                SB.AppendLine("    <EXCEPTION>{2}</EXCEPTION>");
                SB.AppendLine("    <MESSAGE>{3}</MESSAGE>");
                SB.AppendLine("    <SOURCE>{4}</SOURCE>");
                SB.AppendLine("    <STACK>{5}</STACK>");
                SB.AppendLine("    <TARGETSITE>{6}</TARGETSITE>");
                SB.AppendLine("  </LOG>");

                SB.AppendLine("</ERRORLOG>"); // End the xml file

                Log.Write(
                    string.Format(SB.ToString(),
                                  DateTime.Now.ToString("HH:mm:ss"),
                                  Source.ToString(),
                                  Ex.ToString(),
                                  Ex.Message,
                                  Ex.Source,
                                  Ex.StackTrace,
                                  Ex.TargetSite.Name));

                SB = null;
            }
            catch (Exception)
            {
            }
            finally
            {
                if (Log != null)
                {
                    Log.Close();
                }
                Log = null;
                if (LogStream != null)
                {
                    LogStream.Close();
                }
                LogStream = null;
            }
        }
Esempio n. 13
0
 public void Error(ErrorMessageResID resID, LogSource source, Exception exp)
 {
     LogError(resID, source.ToString(), exp);
 }
Esempio n. 14
0
 public static void Write(string strMessage, LogSource Source, LogLevel Level, DateTime LogDate, int intServerID)
 {
     Console.WriteLine(strMessage);
     _YAMS_dbDataSetTableAdapters.YAMS_LogTableAdapter ta = new _YAMS_dbDataSetTableAdapters.YAMS_LogTableAdapter();
     ta.Insert(LogDate, Source.ToString(), strMessage, (int)Level, intServerID);
 }
Esempio n. 15
0
 public void Warning(LogMessageResID resID, LogSource source, params object[] args)
 {
     LogWarning(resID, source.ToString(), args);
 }
Esempio n. 16
0
 public override string ToString()
 {
     return(time.ToString() + ": [" + option.ToString() + "] " + source.ToString() + ": " + data);
 }
Esempio n. 17
0
 public void Error(ErrorMessageResID resID, LogSource source)
 {
     LogError(resID, source.ToString(), null);
 }
Esempio n. 18
0
        internal void LogInformation(string Message, LogSource source = LogSource.Unkown, ulong Guildid = 0, Exception exception = null)
        {
            var Guild = DiscordClient?.GetGuild(Guildid);

            LogEventCustomAsync(new Structs.LogMessage(LogSeverity.Information, source.ToString(), Message, exception, Guild));
        }
Esempio n. 19
0
 public void Info(LogMessageResID resID, LogSource source)
 {
     LogInfo(resID, source.ToString());
 }
Esempio n. 20
0
        /// <summary>
        /// 将日志写入数据库
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="content">内容</param>
        /// <param name="type">类型</param>
        /// <param name="source">来源</param>
        /// <param name="level">级别</param>
        /// <param name="comment">备注</param>
        public static void SaveLog(string title, string content = "", LogType type = LogType.System, LogSource source = LogSource.WebApp, LogLevel level = LogLevel.Info, string comment = "")
        {
            // 获取所有日志类型、来源、级别
            var query    = Restrictions.In("Code", new string[] { "LogType", "LogSource", "LogLevel" });
            var session  = NHibernateHelper.GetCurrentSession();
            var criteria = session.CreateCriteria <DicItem>().CreateCriteria("Dic").Add(query);
            var list     = criteria.List <DicItem>();
            var typeID   = list.Where(o => o.Dic != null && o.Dic.Code == "LogType" && o.Code == type.ToString()).Select(o => o.ID).FirstOrDefault();
            var sourceID = list.Where(o => o.Dic != null && o.Dic.Code == "LogSource" && o.Code == source.ToString()).Select(o => o.ID).FirstOrDefault();
            var levelID  = list.Where(o => o.Dic != null && o.Dic.Code == "LogLevel" && o.Code == level.ToString()).Select(o => o.ID).FirstOrDefault();

            var log = new Log
            {
                AddTime = DateTime.Now,
                AddUser = null,
                Content = content,
                IP      = "127.0.0.1",
                Level   = new DicItem {
                    ID = levelID
                },
                Comment = comment,
                Source  = new DicItem {
                    ID = sourceID
                },
                Status = 0,
                Title  = title,
                Type   = new DicItem {
                    ID = typeID
                }
            };

            if (type == LogType.User) // 用户事件写入IP和用户信息
            {
                log.AddUser = AdminHelper.Admin;
                log.IP      = HttpContext.Current.Request.UserHostAddress;
            }
            session.SaveOrUpdate(log);
            session.Flush();
        }
Esempio n. 21
0
 /// <summary>
 /// Logs the specified message with a debug severity.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="source">The source.</param>
 /// <param name="args">The args.</param>
 public void Warn(string message, LogSource source, params object[] args)
 {
     ILog log = LogManager.GetLogger(source.ToString());
     log.WarnFormat(message, args);
 }
Esempio n. 22
0
 public void Debug(string message, LogSource source)
 {
     LogDebug(message, source.ToString(), null);
 }
Esempio n. 23
0
        /// <summary>
        /// Logs the specified message with a debug severity.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="source">The source.</param>
        /// <param name="args">The args.</param>
        public void Debug(string message, LogSource source, params object[] args)
        {
            ILog log = LogManager.GetLogger(source.ToString());

            log.DebugFormat(message, args);
        }
Esempio n. 24
0
        public void Log(string message, string detail = "", LogLevels logLevel = LogLevels.Spam, LogSource source = LogSource.UNKNOWN)
        {
            LogEntry log = new LogEntry {
                Timestamp = DateTime.UtcNow, Detail = detail, Message = message, LogLevelId = Convert.ToInt32(logLevel), LogType = source.ToString(), HostName = Environment.MachineName
            };

            _loggingRepository.Add(log);
            _loggingRepository.Commit();
        }
Esempio n. 25
0
        private void writeMessage(StreamWriter sw, LogType type, LogSource src, string message, Exception ex, bool writeToConsole)
        {
            string line = getTimeString() + " : " + type.ToString() + " : " + src.ToString() + " : " + message;

            if (ex != null)
                line += ", EXCEPTION: " + ex.ToString();

            sw.WriteLine(line);
            sw.Flush();

            if (writeToConsole)
            {
                switch (type)
                {
                    case (LogType.Error):
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;
                    case (LogType.Warning):
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        break;
                    case (LogType.Progress):
                        break;
                    default:
                        throw new NotImplementedException("Type " + type + " is not handled");
                }

                Console.WriteLine(line);

                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
Esempio n. 26
0
 internal void LogInformation(string Message, LogSource source = LogSource.Unkown, Exception exception = null)
 => LogService.LogEventCustomAsync(new Structs.LogMessage(LogSeverity.Information, source.ToString(), Message, exception, Guild));
Esempio n. 27
0
 public void Debug(string message, LogSource source, params object[] args)
 {
     LogDebug(message, source.ToString(), args);
 }
Esempio n. 28
0
 public static void Write(string strMessage, LogSource Source, LogLevel Level, DateTime LogDate, int intServerID)
 {
     Console.WriteLine(strMessage);
     _YAMS_dbDataSetTableAdapters.YAMS_LogTableAdapter ta = new _YAMS_dbDataSetTableAdapters.YAMS_LogTableAdapter();
     ta.Insert(LogDate, Source.ToString(), strMessage, (int)Level, intServerID);
 }
Esempio n. 29
0
        public void AssertThat_LogSource_StringRepresentation_IsMeaningful()
        {
            var source = new LogSource(new[] { "source-1", "source-2", "source-3" });

            Assert.Equal("[source-1, source-2, source-3]", source.ToString());
        }
Esempio n. 30
0
 public void Warning(LogMessageResID resID, LogSource source)
 {
     LogWarning(resID, source.ToString());
 }