opensourceautomation / Open-Source-Automation

Open Source Automation is a home and commercial automation engine
www.opensourceautomation.com
GNU Lesser General Public License v3.0
97 stars 62 forks source link

Add ability to clear individual server logs #363

Open KHerron opened 7 years ago

KHerron commented 7 years ago

I have already implemented this on my setup and it is working. However, to not pile on more work for the release of 049, I will wait till after the release.

This requires a new Stored Procedure added to the database, and a code change to the OSAE.General.OSAELog and the logs.aspx.cs file. (See Below) This enhancement will only clear the selected log in the Source drop down. To clear all logs, simply select ALL, then click clear. But now you can just clear one log should you need too!

The new stored procedure is as follows:

CREATE DEFINER=`osae`@`%` PROCEDURE `osae_sp_server_log_clear_logger`(IN logID text)
BEGIN
 DELETE
   FROM osae_log
   WHERE Logger = logID;
END

The new code in OSAE.General.OSAELog is as follows:

public static void Clear_Log(string log)
        {
            using (MySqlCommand command = new MySqlCommand())
            {
                command.CommandText = "CALL osae_sp_server_log_clear_logger(@log)";
                command.Parameters.AddWithValue("@log", log);
                try
                { OSAESql.RunQuery(command); }
                catch (Exception ex)
                { throw ex; }
            }
        }

The code changes in the logs.aspx.cs is as follows:

protected void btnClear_Click(object sender, EventArgs e)
    {
        DropDownList ddlSource2 = (DropDownList)gvLog.HeaderRow.FindControl("ddlSource");
        if (ddlSource2.Text == "All")
        {
            OSAE.General.OSAELog.Clear();
        }
        else
        {
            OSAE.General.OSAELog.Clear_Log(ddlSource2.Text);
            Response.Redirect("~/logs.aspx");
        }
        GetLogs();   
    }
KHerron commented 7 years ago

I also added this to the logs.aspx.cs file:

DropDownList ddlSource2 = (DropDownList)gvLog.HeaderRow.FindControl("ddlSource");
btnClear.ToolTip = "Clears " + ddlSource2.Text + " Log Entries";
btnClear2.ToolTip = "Clears " + ddlSource2.Text + " Log Entries";