示例#1
0
        private static void TestData()
        {
            var data = Modification.LoadData <ModificationData>();

            Channel.Log($"TestModification: prev load time {data.LastLoadTime}");
            data.LastLoadTime = DateTime.Now.ToString();
            Channel.Log($"TestModification: current load time {data.LastLoadTime}");
            Modification.SaveData(data);
        }
示例#2
0
        static bool Init()
        {
            channel = new LogChannel("ScriptSystemManaged", Logging.LogSeverity.LS_MESSAGE, new Color(200, 255, 200));


            channel.Log("ScriptSystem.Core initialized\n");
            channel.Log("\tRunning on .NET " + Environment.Version.ToString() + "\n");
            channel.Log("\tOS: " + Environment.OSVersion.ToString() + "\n");
            channel.Log("\tPage Size: " + Environment.SystemPageSize + "\n");
            channel.Log("\tIs 64-bit OS: " + Environment.Is64BitOperatingSystem + "\n");
            channel.Log("\tCore Count: " + Environment.ProcessorCount + "\n");
            return(true);
        }
示例#3
0
        public static void Log(LogRecord record)
        {
            // Check for an active channel
            if (LogChannel == null)
            {
                throw new ArgumentNullException("No log channel! Please enter a valid channel name in to the system configuration table!");
            }

#if NET452
            // Set the app key and environment
            record.AppKey      = ConfigurationManager.AppSettings["AppKey"];
            record.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
                    record.HostIP = HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"];
                }
            }
            catch { }
#elif NETCOREAPP2_2
            // Set the app key and environment
            record.AppKey      = _configuration.GetValue <string>("AppKey");
            record.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
                    record.HostIP = _httpContextAccessor.HttpContext.Connection.LocalIpAddress.ToString();
                }
            }
            catch { }
#endif
            // Check the activity id
            if (String.IsNullOrEmpty(record.LogID))
            {
                record.LogID = GetNextId().ToString();
            }

            // Check the host name
            if (String.IsNullOrEmpty(record.Host))
            {
                record.Host = Environment.MachineName;
            }

            // Check for an incoming exception
            if (record.Exception != null)
            {
                record.ExceptionString = record.Exception.ToString();
            }

            // Check for an incoming data object
            if (record.Data != null)
            {
                record.Data = JsonConvert.SerializeObject(record.Data);
            }

            // Override the time stamps
            record.Created   = DateTime.UtcNow;
            record.TimeStamp = DateTime.UtcNow;

            // Add the log record
            LogChannel.Log(record);
        }
示例#4
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);
        }
示例#5
0
 public static void Log(LogChannel Level, string message)
 {
     Level.Log("[Essentials] " + message);
 }