I use Microsoft Enterprise Library 5.0 (Logging Application Block). I want to save IP address and username into database. How can I add these two columns to 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();
You can write directly as a string Logger.Write("") or you can create your own LogEntry class and inherit from LogEntry and then change the Formatters in the config to include your new properties.
Rereading your question just use extended properties and then change the Formatters in the config.