logviewer.aspx.cs
来自「BugNET is an issue tracking and project 」· CS 代码 · 共 219 行
CS
219 行
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BugNET.BusinessLogicLayer;
using BugNET.UserInterfaceLayer;
using System.Collections.Generic;
namespace BugNET.Administration.Host
{
public partial class LogViewer : System.Web.UI.Page
{
/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
protected void Page_Load(object sender, EventArgs e)
{
if (!ITUser.IsInRole(Globals.SuperUserRole))
Response.Redirect("~/AccessDenied.aspx");
if (!Page.IsPostBack)
{
SortField = "Date";
BindData();
}
}
/// <summary>
/// Handles the RowCreated event of the gvLog control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
protected void gvLog_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
PresentationUtils.SetSortImageStates(gvLog, e.Row,0, SortField, SortAscending);
}
}
/// <summary>
/// Gets or sets the sort field.
/// </summary>
/// <value>The sort field.</value>
string SortField
{
get
{
object o = ViewState["SortField"];
if (o == null)
{
return String.Empty;
}
return (string)o;
}
set
{
if (value == SortField)
{
// same as current sort file, toggle sort direction
SortAscending = !SortAscending;
}
ViewState["SortField"] = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether [sort ascending].
/// </summary>
/// <value><c>true</c> if [sort ascending]; otherwise, <c>false</c>.</value>
bool SortAscending
{
get
{
object o = ViewState["SortAscending"];
if (o == null)
{
return true;
}
return (bool)o;
}
set
{
ViewState["SortAscending"] = value;
}
}
/// <summary>
/// Handles the PageIndexChanging event of the gvLog control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewPageEventArgs"/> instance containing the event data.</param>
protected void gvLog_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvLog.PageIndex = e.NewPageIndex;
BindData();
}
/// <summary>
/// Handles the Sorting event of the gvUsers control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewSortEventArgs"/> instance containing the event data.</param>
protected void gvLog_Sorting(object sender, GridViewSortEventArgs e)
{
SortField = e.SortExpression;
BindData();
}
/// <summary>
/// Binds the data.
/// </summary>
protected void BindData()
{
List<ApplicationLog> list = new List<ApplicationLog>();
list = ApplicationLog.GetLog();
list.Sort(new ApplicationLogComparer(SortField, SortAscending));
gvLog.DataSource = list;
gvLog.DataBind();
}
/// <summary>
/// Handles the RowDataBound event of the gvLog control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="T:System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
protected void gvLog_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
//e.Row.Cells.AddAt(0, new TableCell());
//e.Row.Cells[0].Text = "Total Issues: " + _DataSource.Count;
//e.Row.Cells[0].ColumnSpan = 3;
//e.Row.Cells[0].Font.Bold = true;
//e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Left;
//e.Row.Cells[1].ColumnSpan -= 3;
PresentationUtils.SetPagerButtonStates(gvLog, e.Row, this.Page);
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
ApplicationLog logItem = (ApplicationLog)e.Row.DataItem;
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.FindControl("imgLevel");
img.ImageUrl = GetLogImageUrl(logItem.Level);
img.AlternateText = logItem.Level;
Label LevelLabel = (Label)e.Row.FindControl("LevelLabel");
LevelLabel.Text = logItem.Level;
Label MessageLabel = (Label)e.Row.FindControl("MessageLabel");
MessageLabel.Text = logItem.Message;
Label ExceptionLabel = (Label)e.Row.FindControl("ExceptionLabel");
ExceptionLabel.Text = logItem.Exception;
Label LoggerLabel = (Label)e.Row.FindControl("LoggerLabel");
LoggerLabel.Text = logItem.Logger;
e.Row.Attributes.Add("onclick",string.Format("ExpandDetails('Exception_{0}')",logItem.Id));
}
}
/// <summary>
/// Gets the log image URL.
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
private string GetLogImageUrl(string type)
{
switch (type)
{
case "FATAL":
return "~\\images\\exclamation.gif";
case "ERROR":
return "~\\images\\error.gif";
case "WARNING":
return "~\\images\\Critical.gif";
case "INFO":
return "~\\images\\information.gif";
}
return string.Empty;
}
/// <summary>
/// Handles the Click event of the cmdClearLog control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
protected void cmdClearLog_Click(object sender, EventArgs e)
{
ApplicationLog.ClearLog();
BindData();
}
/// <summary>
/// Handles the SelectedIndexChanged event of the ddlPages control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected void ddlPages_SelectedIndexChanged(Object sender, EventArgs e)
{
GridViewRow gvrPager = gvLog.BottomPagerRow;
if (gvrPager == null)
return;
DropDownList ddlPages = (DropDownList)gvrPager.Cells[0].FindControl("ddlPages");
gvLog.PageIndex = ddlPages.SelectedIndex;
BindData();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?