昨天搞了一晚上,总算把EnterPrise Library Loggin 搞明白了。
创建好就应用后,用Enterprise Library Configuration打开Web.Config或App.Config.
新建Logging Application Block,先在Trace Listeners 新建几个Trace Listeners(是配置写入不同物理位置)如:
flat File Trace Listener 写入文件
DataBase Trace Listener 写入数据库(配置数据库简单不说了,用带的建库SQL建库就好了)
然后在Category Sources 创建几个节点分别设置Trace Listeners
protected void Button1_Click(object sender, EventArgs e)
{
LogEntry errLog = new LogEntry();
errLog.Message = this.TextBox1.Text;
errLog.Severity = System.Diagnostics.TraceEventType.Error;//设定消息类型
Logger.Write(errLog, "Message");//Message 是以上Category Sources 定义的名称
}
protected void Button2_Click(object sender, EventArgs e)
{
LogEntry errLog = new LogEntry();
errLog.Message = this.TextBox2.Text;
errLog.Severity = System.Diagnostics.TraceEventType.Information;
Logger.Write(errLog, "Error");
}
protected void Button3_Click(object sender, EventArgs e)
{
LogEntry errLog = new LogEntry();
errLog.Message = this.TextBox3.Text;
errLog.Severity = System.Diagnostics.TraceEventType.Information;
Logger.Write(errLog, "Operator");
}