Quick Application Logger Code
//todo: check anonymous (elevated privileges?)
public class Log
{
private const string LogSource = "mYsOURCE";
public static void WriteEntry(Exception Event)
{
string sSource = LogSource;
string sLog = "Application";
SPSecurity.RunWithElevatedPrivileges(() =>
{
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
try
{
EventLog.WriteEntry(sSource, Event.ToString());
}
catch { }
});
}
public static void WriteEntry(string msg)
{
string sSource = LogSource;
string sLog = "Application";
SPSecurity.RunWithElevatedPrivileges(() =>
{
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
try
{
EventLog.WriteEntry(sSource, msg);
}
catch { }
});
}
public static void WriteErrorEntry(Exception Event)
{
string sSource = LogSource;
string sLog = "Application";
SPSecurity.RunWithElevatedPrivileges(() =>
{
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
try
{
EventLog.WriteEntry(sSource, Event.ToString(), EventLogEntryType.Error);
}
catch { }
});
}
public static void WriteErrorEntry(string msg)
{
string sSource = LogSource;
string sLog = "Application";
SPSecurity.RunWithElevatedPrivileges(() =>
{
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
try
{
EventLog.WriteEntry(sSource, msg, EventLogEntryType.Error);
}
catch { }
});
}
}
public class Log
{
private const string LogSource = "mYsOURCE";
public static void WriteEntry(Exception Event)
{
string sSource = LogSource;
string sLog = "Application";
SPSecurity.RunWithElevatedPrivileges(() =>
{
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
try
{
EventLog.WriteEntry(sSource, Event.ToString());
}
catch { }
});
}
public static void WriteEntry(string msg)
{
string sSource = LogSource;
string sLog = "Application";
SPSecurity.RunWithElevatedPrivileges(() =>
{
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
try
{
EventLog.WriteEntry(sSource, msg);
}
catch { }
});
}
public static void WriteErrorEntry(Exception Event)
{
string sSource = LogSource;
string sLog = "Application";
SPSecurity.RunWithElevatedPrivileges(() =>
{
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
try
{
EventLog.WriteEntry(sSource, Event.ToString(), EventLogEntryType.Error);
}
catch { }
});
}
public static void WriteErrorEntry(string msg)
{
string sSource = LogSource;
string sLog = "Application";
SPSecurity.RunWithElevatedPrivileges(() =>
{
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
try
{
EventLog.WriteEntry(sSource, msg, EventLogEntryType.Error);
}
catch { }
});
}
}
Comments
Post a Comment