示例#1
0
        public void Add(NetStashEvent log)
        {
            Entities.Log addLog = new Entities.Log();
            //addLog.Message = Newtonsoft.Json.JsonConvert.SerializeObject(log);

            //Microsoft.AspNetCore.Formatter.Json
            string JsonString = log.GetJson();

            addLog.Message = JsonString;

            using (IDbConnection db = NetStashStandard.Log.NetStashLog.TypeNet == Log.TypeNet.NetCore ? baseProxy.GetConnectionSqlite() : baseProxy.GetConnection())

                using (IDbCommand cmd = db.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO Log (Message) VALUES (@Message)";
                    cmd.CommandType = CommandType.Text;
                    IDbDataParameter pMessage = cmd.CreateParameter();
                    pMessage.ParameterName = "@Message";
                    pMessage.Value         = addLog.Message;
                    cmd.Parameters.Add(pMessage);
                    cmd.Prepare();
                    db.Open();
                    cmd.ExecuteNonQuery();
                }
        }
示例#2
0
        public void Fatal(string message, System.Reflection.MethodBase currentMethod, string OldValue = "", string NewValue = "")
        {
            NetStashEvent netStashEvent = new NetStashEvent();

            netStashEvent.Level   = NetStashLogLevel.Fatal.ToString();
            netStashEvent.Message = message;
            netStashEvent.Method  = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;
            netStashEvent.Fields  = GetFields(OldValue, NewValue);
            this.AddSendToLogstash(netStashEvent);
        }
示例#3
0
        public void Debug(string message, Dictionary <string, string> values = null)
        {
            NetStashEvent netStashEvent = new NetStashEvent();

            netStashEvent.Level   = NetStashLogLevel.Debug.ToString();
            netStashEvent.Message = message;
            netStashEvent.Fields  = values;

            this.AddSendToLogstash(netStashEvent);
        }
示例#4
0
        internal void InternalError(string message, Dictionary <string, string> values = null)
        {
            NetStashEvent netStashEvent = new NetStashEvent();

            netStashEvent.Level   = NetStashLogLevel.Error.ToString();
            netStashEvent.Message = message;
            netStashEvent.Fields  = values;

            this.AddSendToLogstash(netStashEvent, false);
        }
示例#5
0
        public void Error(Exception exception, Dictionary <string, string> values)
        {
            NetStashEvent netStashEvent = new NetStashEvent();

            netStashEvent.Level            = NetStashLogLevel.Error.ToString();
            netStashEvent.Message          = exception.Message;
            netStashEvent.ExceptionDetails = exception.StackTrace;
            netStashEvent.Fields           = values;

            this.AddSendToLogstash(netStashEvent);
        }
示例#6
0
        public void Error(Exception exception, System.Reflection.MethodBase currentMethod, string OldValue = "", string NewValue = "")
        {
            NetStashEvent netStashEvent = new NetStashEvent();

            netStashEvent.Level            = NetStashLogLevel.Error.ToString();
            netStashEvent.Message          = exception.Message;
            netStashEvent.ExceptionDetails = exception.StackTrace;
            netStashEvent.Method           = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;
            netStashEvent.Fields           = GetFields(OldValue, NewValue);

            this.AddSendToLogstash(netStashEvent);
        }
示例#7
0
        private void AddSendToLogstash(NetStashEvent e, bool run = true)
        {
            e.Machine = Environment.MachineName;
            e.Source  = system;
            e.Index   = logname;

            Storage.Proxy.LogProxy proxy = new Storage.Proxy.LogProxy();
            proxy.Add(e);

            if (run)
            {
                Worker.TcpWorker.Run();
            }
        }
示例#8
0
        /// <summary>
        /// Registra um novo evento de log
        /// </summary>
        /// <param name="level">Nivel do log</param>
        /// <param name="message">Mensagem descritiva do log</param>
        /// <param name="exception">Exceçao que sera logado</param>
        /// <param name="addtionalValues">Valores adicionais que serao incluidos no log</param>
        public void Log(NetStashLogLevel level, string message, Exception exception,
                        Dictionary <string, string> addtionalValues)
        {
            var netStashEvent = new NetStashEvent
            {
                Level            = level.ToString(),
                Message          = message,
                ExceptionMessage = exception?.Message,
                ExceptionDetails = exception?.StackTrace,
                Fields           = addtionalValues
            };

            AddSendToLogstash(netStashEvent);
        }
示例#9
0
        private void AddSendToLogstash(NetStashEvent e, bool run = true)
        {
            e.Machine    = Environment.MachineName;
            e.MacAddress = (from nic in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up select nic.GetPhysicalAddress().ToString()).FirstOrDefault();
            e.AppVersion = currentAppVersion;
            e.Username   = user;

            Storage.Proxy.LogProxy proxy = new Storage.Proxy.LogProxy();
            proxy.Add(e);

            if (run)
            {
                Worker.TcpWorker.Run();
            }
        }
示例#10
0
        /// <summary>
        /// Adiciona uma nova mensagem no banco de dados
        /// </summary>
        /// <param name="log">Evento que sera adicionado</param>
        public void Add(NetStashEvent log)
        {
            Entities.Log addLog = new Entities.Log();
            addLog.Message = Newtonsoft.Json.JsonConvert.SerializeObject(log.ToDictionary());

            using (IDbConnection db = base.GetConnection())
                using (IDbCommand cmd = db.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO Log (Message) VALUES (@Message)";
                    cmd.CommandType = CommandType.Text;
                    IDbDataParameter pMessage = cmd.CreateParameter();
                    pMessage.ParameterName = "@Message";
                    pMessage.Value         = addLog.Message;
                    cmd.Parameters.Add(pMessage);
                    db.Open();
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }
        }
示例#11
0
        public void Information(string message, System.Reflection.MethodBase currentMethod, string OldValue = "", string NewValue = "")
        {
            NetStashEvent netStashEvent = new NetStashEvent();

            netStashEvent.Level   = NetStashLogLevel.Information.ToString();
            netStashEvent.Message = message;
            netStashEvent.Method  = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;
            Dictionary <string, string> Fields = new Dictionary <string, string>();

            if (OldValue.Length > 0)
            {
                Fields.Add("OldValue", OldValue);
            }
            if (NewValue.Length > 0)
            {
                Fields.Add("NewValue", NewValue);
            }
            netStashEvent.Fields = Fields;

            this.AddSendToLogstash(netStashEvent);
        }
示例#12
0
        public void Error(Exception exception, System.Reflection.MethodBase currentMethod, string OldValue = "", string NewValue = "")
        {
            NetStashEvent netStashEvent = new NetStashEvent();

            netStashEvent.Level            = NetStashLogLevel.Error.ToString();
            netStashEvent.Message          = exception.Message;
            netStashEvent.ExceptionDetails = exception.StackTrace;
            netStashEvent.Method           = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;
            Dictionary <string, string> Fields = new Dictionary <string, string>();

            if (OldValue.Length > 0)
            {
                Fields.Add("OldValue", OldValue);
            }
            if (NewValue.Length > 0)
            {
                Fields.Add("NewValue", NewValue);
            }
            netStashEvent.Fields = Fields;

            this.AddSendToLogstash(netStashEvent);
        }