STEP 1: Create a class file like ErrorHelper.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace VCSB.INTRANET.BLL
{
public class ErrorHelper
{
#region LoginName
/// <summary>
/// Get Currnet user Loginame
/// </summary>
public static string LoginName
{
get
{
SPSite spSite; SPWeb spWeb;
using (spSite = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = spSite.OpenWeb())
{
SPUser sUser = spWeb.CurrentUser;
//string str = sUser.Name + sUser.LoginName + sUser.Email + sUser.Groups.Count;
return sUser.LoginName;
}
}
}
}
#endregion
#region Add
public static void Add(string message, string stacktrace)
{
try
{
SPSite spSite; SPWeb spWeb; SPList spList;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (spSite = new SPSite(SPContext.Current.Site.Url))
{
spSite.AllowUnsafeUpdates = true;
using (spWeb = spSite.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPWeb objweb = spSite.OpenWeb();
spList = spWeb.Lists.TryGetList("ErrorLog");
if (spList != null)
{
SPListItem spListItem = spList.Items.Add();
spWeb.AllowUnsafeUpdates = true;
spListItem["ErrorMessage"] = Convert.ToString(message);
spListItem["StackTrace"] = Convert.ToString(stacktrace);
spListItem["LoginName"] = Convert.ToString(LoginName);
spListItem.Update();
}
}
spWeb.AllowUnsafeUpdates = false;
}
spSite.AllowUnsafeUpdates = false;
});
}
catch { }
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace VCSB.INTRANET.BLL
{
public class ErrorHelper
{
#region LoginName
/// <summary>
/// Get Currnet user Loginame
/// </summary>
public static string LoginName
{
get
{
SPSite spSite; SPWeb spWeb;
using (spSite = new SPSite(SPContext.Current.Site.Url))
{
using (spWeb = spSite.OpenWeb())
{
SPUser sUser = spWeb.CurrentUser;
//string str = sUser.Name + sUser.LoginName + sUser.Email + sUser.Groups.Count;
return sUser.LoginName;
}
}
}
}
#endregion
#region Add
public static void Add(string message, string stacktrace)
{
try
{
SPSite spSite; SPWeb spWeb; SPList spList;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (spSite = new SPSite(SPContext.Current.Site.Url))
{
spSite.AllowUnsafeUpdates = true;
using (spWeb = spSite.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPWeb objweb = spSite.OpenWeb();
spList = spWeb.Lists.TryGetList("ErrorLog");
if (spList != null)
{
SPListItem spListItem = spList.Items.Add();
spWeb.AllowUnsafeUpdates = true;
spListItem["ErrorMessage"] = Convert.ToString(message);
spListItem["StackTrace"] = Convert.ToString(stacktrace);
spListItem["LoginName"] = Convert.ToString(LoginName);
spListItem.Update();
}
}
spWeb.AllowUnsafeUpdates = false;
}
spSite.AllowUnsafeUpdates = false;
});
}
catch { }
}
#endregion
}
}
No comments:
Post a Comment