alfinete
Power Member
bom dia
no c# estão a criar uma entrada no event viewer do windows 10
mas eu quero criar um novo source
se não criar novo source corre bem e insere
____________________________________________________________
se puser a criar novo source esta a dar o seguinte erro
no c# estão a criar uma entrada no event viewer do windows 10
mas eu quero criar um novo source
se não criar novo source corre bem e insere
____________________________________________________________
Código:
/// <summary>
///
/// </summary>
/// <param name="IsError"></param>
/// <param name="MsgError"></param>
public static void SaveEventViewer(bool IsError, string MsgError,string InfoSource, string LogName)
{
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry(MsgError, !IsError ? EventLogEntryType.Information : EventLogEntryType.Error, 101, 1);
}
}
se puser a criar novo source esta a dar o seguinte erro
Código:
public static void AddMessageToEventLog(string MsgError, EventType type,string InfoSource, int id)
{
try
{
EventLog elog = new EventLog("");
if (!EventLog.SourceExists(InfoSource))
{
EventLog.CreateEventSource(InfoSource, "Application");
}
elog.Source = InfoSource;
elog.EnableRaisingEvents = true;
EventLogEntryType entryType = EventLogEntryType.Error;
switch (type)
{
case EventType.ERROR:
entryType = EventLogEntryType.Error;
break;
case EventType.INFORMATION:
entryType = EventLogEntryType.Information;
break;
case EventType.WARNING:
entryType = EventLogEntryType.Warning;
break;
}
elog.WriteEntry(MsgError, entryType, id);
}
catch (System.Security.SecurityException secError)
{
// If the user don't have administrator rights a SecurityException will be
// thrown if the source didn't exist.
// You need to handle this...
}
catch (Exception eventError)
{
// Catch other exceptions that can happen when you try to write to
// the event log...
}
}