Example #1
0
        private void frmLog_Load(object sender, EventArgs e)
        {
            try
            {
                Setup();

                txtLog.ConfigurationManager.Language = "mssql";
                txtLog.ConfigurationManager.Configure();
                //txtLog.Text = string.Empty;
                //var filePath = @"C:\Temp\DB Tool\";
                //var fileName = DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + ".txt";
                //if (!Directory.Exists(filePath))
                //{
                //    Directory.CreateDirectory(filePath);
                //}
                //if (File.Exists(filePath + fileName))
                //{
                //    txtLog.Text = File.ReadAllText(filePath + fileName);
                //}

                var data = new QueryLog.Data();
                data.ConnectionId = ConnectionId;
                data.FromDate     = DateTime.Today;

                var logList = QueryLog.Search(data);
                if (logList != null && logList.Rows.Count > 0)
                {
                    foreach (DataRow dr in logList.Rows)
                    {
                        var dt = Convert.ToDateTime(dr["CreatedDate"]);
                        txtLog.AppendText("--------Executed on: " + dt.ToString("MM-dd-yyyy") + " " + dt.Hour + ":" + dt.Minute + ":" + dt.Second + "-------\n");
                        txtLog.AppendText(Convert.ToString(dr["QueryText"]) + "\n");
                        txtLog.AppendText("\n");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void LoadSQLLog()
        {
            txtLog.ResetText();
            var data = new QueryLog.Data();

            data.ConnectionId = ConnectionId;
            data.FromDate     = DateTime.Today;

            var logList = QueryLog.Search(data);

            if (logList != null && logList.Rows.Count > 0)
            {
                foreach (DataRow dr in logList.Rows)
                {
                    var dt = Convert.ToDateTime(dr["CreatedDate"]);
                    txtLog.AppendText("--------Executed on: " + dt.ToString("MM-dd-yyyy") + " " + dt.Hour + ":" + dt.Minute + ":" + dt.Second + "-------\n");
                    txtLog.AppendText(Convert.ToString(dr["QueryText"]) + "\n");
                    txtLog.AppendText("\n");
                }
            }
        }
Example #3
0
        public override void Log(string expression, object value)
        {
            string log = null;

            if (value != null && value.GetType() != typeof(string))
            {
                var enumerable = value as IEnumerable;
                if (enumerable != null)
                {
                    var sb = new StringBuilder();

                    foreach (var item in enumerable)
                    {
                        if (item == null)
                        {
                            sb.AppendLine("(null)");
                        }
                        else
                        {
                            sb.AppendLine(item.ToString());
                        }
                    }
                    value = sb.ToString();
                }
            }

            if (value == null)
            {
                value = "(null)";
            }
            if (value == DBNull.Value)
            {
                value = "(DBNull)";
            }

            if (!string.IsNullOrEmpty(expression) && value != null)
            {
                log = ">> " + expression + Environment.NewLine + value.ToString();
            }
            else
            {
                if (!string.IsNullOrEmpty(expression))
                {
                    log = ">> " + expression;
                }
                else
                {
                    log = value.ToString();
                }
            }

            _box.AppendText(log + Environment.NewLine + Environment.NewLine);
        }