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

Popular posts from this blog

[SOLVED] The SharePoint Timer Service service terminated unexpectedly. Event ID : 7031

FIX : The password supplied with the username Domain\Username was not correct. Verify that it was entered correctly and try again.

FIX : stsadm is not recognized as an internal command