private void LogSQL(string sql)
        {
            //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);
            //}

            //StreamWriter sw = null;
            //if (!File.Exists(filePath + fileName))
            //{
            //    sw = File.CreateText(filePath + fileName);
            //}
            //else
            //{
            //    sw = File.AppendText(filePath + fileName);
            //}

            //sw.WriteLine("--------Executed on: " + DateTime.Now.ToString("MM-dd-yyyy") + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second + "--------");
            //sw.WriteLine(sql);
            //sw.WriteLine("");

            //sw.Close();

            var data = new QueryLog.Data();

            data.ConnectionId = ConnectionId;
            data.ViewId       = 0;
            data.QueryText    = sql;
            data.CreatedDate  = DateTime.Now;
            QueryLog.Create(data, ApplicationConnectionString);
        }
Exemplo n.º 2
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");
                }
            }
        }