/// <summary>
        /// Logs the message either as Error/Debug/Warning into a separate folder with file name.
        /// </summary>
        /// <param name="strModule">File Name</param>
        /// <param name="strMethodName">Folder Name that created in the log folder</param>
        /// <param name="strMsg">Message to display in the log</param>
        /// <param name="type">Log type</param>
        public static void LogWriter(string strModule, string strMethodName, string strMsg, LogMode type)
        {
            try
            {
                log4net.GlobalContext.Properties["LogFileName"] = strModule;
                log4net.Config.XmlConfigurator.Configure();

                ILog log = LogManager.GetLogger(typeof(Log4net));

                if (type.ToString() == "Error")
                {
                    log.Error(strMethodName + " | Message : " + strMsg);
                }
                else if (type.ToString() == "Warn")
                {
                    log.Warn(strMethodName + " | Message : " + strMsg);
                }
                else if (type.ToString() == "Debug")
                {
                    log.Debug(strMethodName + " | Message : " + strMsg);
                }
            }
            catch (Exception ex)
            {
                log.Error("Error in Log : " + ex.Message);
            }
        }
Beispiel #2
0
 public static void Write(string format, LogMode logMode, params object[] args)
 {
     if (LoggingLevel <= logMode)
     {
         Out?.Invoke($"[{logMode.ToString().PadRight(LongestLogModeNameLength, PaddingChar)}] [{DateTime.UtcNow.ToString("O")}] {format}", args);
     }
 }
Beispiel #3
0
        internal LogBase(LogLevel level, LogMode mode, bool consoleApp)
        {
            _loglevel = level;

            // packer encodings
            switch (mode)
            {
            case LogMode.Console:
                _initialEncoding = _targetEncoding;
                break;

            case LogMode.File:
                if (consoleApp)
                {
                    _targetEncoding = _initialEncoding;
                }
                else
                {
                    _targetEncoding = Encoding.Default;
                }
                break;

            default:
                throw new NotImplementedException(mode.ToString());
            }
        }
Beispiel #4
0
		private static void Out(string message, LogMode logMode = LogMode.Info)
		{
			if(mode != Configuration.eMode.Development)
			{
				return;
			}

			message.Insert(0, "[" + logMode.ToString() + "] ");

			switch(logMode)
			{
				default:
				case LogMode.Info:
					Debug.Log(message);
					break;

				case LogMode.Warning:
					Debug.LogWarning(message);
					break;

				case LogMode.Error:
					Debug.LogError(message);
					break;

				case LogMode.Fatal:
#if UNITY_EDITOR
					EditorApplication.isPaused = true;
#endif
					throw new Exception(message);
			}
		}
Beispiel #5
0
        public void Log(LogMode mode, string message)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("[{0}]\t", mode.ToString());
            sb.AppendFormat("{0}{1}", message, Environment.NewLine);

            File.AppendAllText(_fileName, sb.ToString());
        }
Beispiel #6
0
 // private static LogFactory factory;
 protected LogHandler(LogMode logMode)
 {
     logger     = LogManager.GetCurrentClassLogger();
     LoggerMode = logMode;
     //if (factory == null)
     //{
     //    //加载配置
     //    factory = LogManager.LoadConfiguration(Directory.GetCurrentDirectory() + "/Configs/nlog.config");
     //}
     logger = logger.Factory.GetLogger(LoggerMode.ToString());
 }
Beispiel #7
0
        private void Message(LogMode logMode, string text, params object[] args)
        {
            //處理字串
            text = (args.Length == 0) ? text : string.Format(text, args);

            LogEventInfo logEventInfo = new LogEventInfo();

            logEventInfo.TimeStamp = DateTime.Now;

            if (logMode != LogMode.error)
            {
                logEventInfo.Level = LogLevel.Info;
                logEventInfo.Properties["FolderName"] = logMode.ToString();
                logEventInfo.Properties["LogName"]    = logMode.ToString() + string.Format("_{0}", DateTime.Now.Hour.ToString());
                loggerByHour.Log(logEventInfo);
            }
            else
            {
                logEventInfo.Properties["LogName"] = logMode.ToString();
                logEventInfo.Level = (logMode != LogMode.error) ? LogLevel.Info : LogLevel.Error;
                loggerByDay.Log(logEventInfo);
            }
        }
Beispiel #8
0
        void IUILogger.Log(LogMode logMode, string message, Exception exception, bool logToUI)
        {
            string logModePrefix    = string.Format("[{0}]", logMode.ToString().ToUpper());
            string exceptionMessage = string.Empty;

            if (exception != null)
            {
                exceptionMessage = string.Concat(" - [Exception: ", exception, "]");
            }

            switch (logMode)
            {
            case LogMode.Debug:
                _log.Debug(_messagePrefix + message, exception);
                break;

            case LogMode.Info:
                _log.Info(_messagePrefix + message, exception);
                break;

            case LogMode.Warn:
                _log.Warn(_messagePrefix + message, exception);
                break;

            case LogMode.Error:
                _log.Error(_messagePrefix + message, exception);
                break;

            case LogMode.Fatal:
                _log.Fatal(_messagePrefix + message, exception);
                break;
            }

            if (logToUI)
            {
                Console.WriteLine(string.Concat(logModePrefix, _messagePrefix, " ", message, exceptionMessage));
            }
        }
Beispiel #9
0
        public void Log(LogMode level, string message, Exception exception)
        {
            // Get the process id from the http context
            var process = HttpContext.Items.Contains("Process") ? HttpContext.Items["Process"].ToString() : string.Empty;

            // Create the logrecord
            var logRecord = new LogRecord()
            {
                TenantId      = "x",
                ApplicationId = "x",
                ApplicationIp = HttpContext.Request.ServerVariables["LOCAL_ADDR"],
                UserId        = UserId.ToString(),
                Level         = level.ToString(),
                Process       = process,
                ThreadId      = ThreadId,
                Message       = message,
                Exception     = exception,
                //Data = data
            };

            // Log to the central logging system
            //LogService.Log(logRecord);
        }
Beispiel #10
0
        private static String Format(string text, LogMode mode)
        {
            var trace  = new StackTrace(3);
            var caller = trace.GetFrame(0);

            return(String.Format("[{0}][{1}][{3}#{4}] {2}", DateTime.Now.ToString("HH':'mm':'ss"), mode.ToString().ToUpper(), text, caller.GetMethod().DeclaringType.Name, caller.GetMethod().Name, caller.GetFileLineNumber()));
        }
 /// <summary>
 /// Method to translate <see cref="LogMode"/>.
 /// </summary>
 /// <param name="logMode"><see cref="LogMode"/>.</param>
 /// <returns>Translated <see cref="LogMode"/>.</returns>
 public string Translate(LogMode logMode)
 {
     return(Translate(logMode.ToString()));
 }
Beispiel #12
0
        public static void Log(LogMode mode, string message, Exception ex, string process = "", object data = null)
        {
            // Check for an active log channel
            if (LogChannel == null)
            {
                throw new ArgumentNullException("No active log channel! Please enter a valid channel name in to the system configuration table!");
            }

            // Check the log level
            if (mode < Mode)
            {
                return;
            }

            // Create the log entry
            LogRecord logRecord = new LogRecord
            {
                LogID           = GetNextId().ToString(),
                Process         = process,
                Host            = Environment.MachineName,
                Level           = mode.ToString(),
                Message         = message,
                Exception       = ex,
                ExceptionString = ex == null ? string.Empty : ex.ToString(),
                Data            = data,
                DataString      = data == null ? string.Empty : JsonConvert.SerializeObject(data),
                Created         = DateTime.UtcNow,
                TimeStamp       = DateTime.UtcNow
            };

#if NET452
            // Set the app key and environment
            logRecord.AppKey      = ConfigurationManager.AppSettings["AppKey"];
            logRecord.Environment = ConfigurationManager.AppSettings["Environment"];

            // Try to get the host ip
            try
            {
                if (HttpContext.Current != null && HttpContext.Current.Request != null && !string.IsNullOrEmpty(HttpContext.Current.Request.UserHostAddress))
                {
                    // Set the host ip
                    logRecord.HostIP = HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"];
                }
            }
            catch { }
#elif NETCOREAPP2_2
            // Set the app key and environment
            logRecord.AppKey      = _configuration.GetValue <string>("AppKey");
            logRecord.Environment = _configuration.GetValue <string>("Environment");

            // Try to get the host ip
            try
            {
                if (_httpContextAccessor.HttpContext != null && _httpContextAccessor.HttpContext.Request != null && !string.IsNullOrEmpty(_httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString()))
                {
                    // Set the host ip
                    logRecord.HostIP = _httpContextAccessor.HttpContext.Connection.LocalIpAddress.ToString();
                }
            }
            catch { }
#endif
            // Log with the default channel
            LogChannel.Log(logRecord);
        }
Beispiel #13
0
 public static void Log(string Message, LogMode Mode = LogMode.Error)
 {
     System.Windows.MessageBox.Show(Message, Program + " - " + Mode.ToString(), MessageBoxButton.OK, ((Mode == LogMode.Error) ? MessageBoxImage.Error : MessageBoxImage.Information));
 }