【发布时间】:2011-01-29 07:49:58
【问题描述】:
我使用 Microsoft Enterprise Library 5.0(记录应用程序块)。我想将 IP 地址和用户名保存到数据库中。如何将这两列添加到 Logging Application Block?
HttpContext _Context = HttpContext.Current;
Exception _ex = _Context.Server.GetLastError();
LogEntry _LogEntery = new LogEntry();
if (_ex.InnerException != null)
{
_LogEntery.Message = _ex.InnerException.ToString();
}
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
_ex.Data.Add("UserName", HttpContext.Current.User.Identity.Name);
}
_ex.Data.Add("IPaddress", Request.UserHostAddress);
_LogEntery.Title = _ex.Message.ToString();
_LogEntery.ExtendedProperties.Add("Ip", _ex.Data["IPaddress"]);
_LogEntery.Categories.Add("Database");
Logger.Write(_LogEntery);
_Context.Server.ClearError();
【问题讨论】:
-
@Tuzo,感谢您提供的信息!我怀疑该特定问题会有一个片段 ID,但没有花时间查找它。下次我会使用直接超链接。
标签: c# asp.net enterprise-library logging-application-block