protected void ExceptionLog(Exception ex)
{
using (SPSite oSite = new SPSite(siteURL))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPList olist = oWeb.Lists["ErrorLog"];
oWeb.AllowUnsafeUpdates = true;
SPListItem itemToAdd = olist.Items.Add();
itemToAdd["HelpLink"] = ex.HelpLink;
itemToAdd["Message"] = ex.Message;
itemToAdd["Source"] = ex.Source;
itemToAdd["StackTrace"] = ex.StackTrace;
itemToAdd["TargetSite"] = ex.TargetSite;
SPUser oUser = oWeb.EnsureUser(oWeb.CurrentUser.LoginName);
itemToAdd["UserName"] = oUser;
itemToAdd["Module"] = ex.TargetSite.DeclaringType;
itemToAdd.Update();
oWeb.AllowUnsafeUpdates = false;
//Response.Redirect("/SitePages/Error.aspx", false);
}
}
}
{
using (SPSite oSite = new SPSite(siteURL))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPList olist = oWeb.Lists["ErrorLog"];
oWeb.AllowUnsafeUpdates = true;
SPListItem itemToAdd = olist.Items.Add();
itemToAdd["HelpLink"] = ex.HelpLink;
itemToAdd["Message"] = ex.Message;
itemToAdd["Source"] = ex.Source;
itemToAdd["StackTrace"] = ex.StackTrace;
itemToAdd["TargetSite"] = ex.TargetSite;
SPUser oUser = oWeb.EnsureUser(oWeb.CurrentUser.LoginName);
itemToAdd["UserName"] = oUser;
itemToAdd["Module"] = ex.TargetSite.DeclaringType;
itemToAdd.Update();
oWeb.AllowUnsafeUpdates = false;
//Response.Redirect("/SitePages/Error.aspx", false);
}
}
}
How to write logging statements to the methods and save to sharepoint list programatically?
ReplyDelete