Write an EventLog C# - SharePoint
# Create a new class called Logger
using System.Diagnostics;
public class Logger
{
string sSource;
string sLog;
public void EventLogWriter(string message)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
sSource = "SBS | Credit Approval";
sLog = "Application";
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, message, EventLogEntryType.Error, 1);
});
}
}
In the C# application Page
Logger log = new Logger ();
try
{
}
catch (Exception ex )
{
log.EventLogWriter("System : Your System Name || Method : Your Method Name|| ERROR : " + ex.Message);
}
----------------------------- Regards : Shashika Hettiarachchi -----------------------------
Comments
Post a Comment