本文整理汇总了C#中EventLogEntryType类的典型用法代码示例。如果您正苦于以下问题:C# EventLogEntryType类的具体用法?C# EventLogEntryType怎么用?C# EventLogEntryType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventLogEntryType类属于命名空间,在下文中一共展示了EventLogEntryType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Print
/// <summary>
/// Prints a message to the local systems eventlog.
/// </summary>
/// <param name="entry"></param>
/// <param name="type"></param>
private static void Print(string entry, EventLogEntryType type)
{
switch (type)
{
case EventLogEntryType.Error: entry = "[error]: " + entry; break;
case EventLogEntryType.Information: entry = "[comment]: " + entry; break;
case EventLogEntryType.Warning: entry = "[warning]: " + entry; break;
}
try
{
if (EventLog.Exists("Application", "."))
{
EventLog eventLog = new EventLog("Application", ".", "EasyHook");
#if !DEBUG
if(InType == EventLogEntryType.Error)
#endif
eventLog.WriteEntry(entry, type);
}
}
catch
{
}
#if DEBUG
Console.WriteLine(entry);
#endif
}
示例2: AddWindowsEventLog
private void AddWindowsEventLog(string message, EventLogEntryType logType = EventLogEntryType.Information, string moduleName = "", int codeErreur = 0, bool fromFileLogEvent = false)
{
EventLog evLog = new EventLog(Const.WINDOWS_LOG_NAME);
message = string.Concat(message, "\r\n", "Module : ", moduleName);
evLog.Source = Const.DEFAULT_APPLICATION_NAME;
InitWindowsEventLog();
try
{
evLog.WriteEntry(message, logType, codeErreur);
}
catch (Exception ex)
{
if (!fromFileLogEvent)
{
AddFileEventLog("Impossible d'écrire dans le journal de log " + Log.Const.WINDOWS_LOG_NAME + ".\r\nLe journal doit être créé préalablement avec un compte Administrateur.\r\nMessage :\r\n" + message + "\r\nException : " + ex.Message, logType, moduleName, codeErreur, true);
}
}
finally
{
evLog.Close();
}
}
示例3: EventlogListener
public EventlogListener(string protocol, string source, string category, EventLogEntryType[] types, string key, int value, IMonitoringChannel channel)
{
if (protocol == null)
throw new ArgumentNullException("protocol");
if (key == null)
throw new ArgumentNullException("key");
if (channel == null)
throw new ArgumentNullException("channel");
this.key = key;
this.value = value;
this.channel = channel;
this.types = types;
this.protocol = protocol;
this.source = source;
this.category = category;
try
{
this.Initialize();
}
catch (ArgumentException exception)
{
throw new ArgumentException(
exception.Message + " (" + protocol + ")",
exception);
}
}
示例4: LoggingUtil
public LoggingUtil(EventLogEntryType min, EventLogEntryType max, String applicationName)
{
isSytemEvent = true;
minSysLevel = min;
maxSysLevel = max;
_logFile.Source = applicationName;
}
示例5: WriteEntry
//Write entry log with custome event log entry type
public void WriteEntry(string message, EventLogEntryType entryType)
{
if (enableDebugLog)
{
debugLog.WriteEntry(message, entryType);
}
}
示例6: Log
/// <summary/>
/// <param name="message"/>
/// <param name="eventLogType"/>
/// <exclude/>
public virtual void Log(string message, EventLogEntryType eventLogType)
{
lock (lockObj)
{
this.eventLog.WriteEntry(message, eventLogType, this.eventId);
}
}
示例7: EventLog
static void EventLog(String evt, EventLogEntryType tpy)
{
if (bEventLog)
eventLog.WriteEntry(evt, tpy);
//Console.WriteLine(evt);
//MessageBox.Show(evt);
}
示例8: WriteEventLogEntry
public void WriteEventLogEntry(string Message, EventLogEntryType type)
{
if(_eventLog!=null)
_eventLog.WriteEntry(Message, type);
else
throw new Exception("Unable to write to event log : not initialized. \r\nMessage to write:\r\n" + Message);
}
示例9: Log
public static void Log(string message, EventLogEntryType logType, [CallerMemberName] string memberName = "",
[CallerLineNumber] int lineNumber = 0) {
try {
using (StreamWriter log = new StreamWriter("logs.txt", true)) {
string _out =
$"[{DateTime.Now.ToString("dd/MM hh:mm")} {Enum.GetName(typeof(EventLogEntryType), logType)}] ";
switch (logType) {
case EventLogEntryType.SuccessAudit:
case EventLogEntryType.FailureAudit:
case EventLogEntryType.Warning:
case EventLogEntryType.Error:
_out += $"from `{memberName}' at {lineNumber}: {message}";
Console.WriteLine(_out);
log.WriteLine(_out);
log.Flush();
break;
case EventLogEntryType.Information:
_out += message;
Console.WriteLine(_out);
log.WriteLine(_out);
log.Flush();
break;
default:
throw new ArgumentOutOfRangeException(nameof(logType), logType, null);
}
}
} catch (Exception ex) {
Console.WriteLine($"||| Logging error occured: {ex}", EventLogEntryType.Error);
}
}
示例10: Write
private static void Write(string message, EventLogEntryType type)
{
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, "Application");
EventLog.WriteEntry(sSource, message, type, eventID);
}
示例11: WriteEventLog
private static void WriteEventLog(string source, string content, EventLogEntryType type)
{
try
{
if (!EventLog.SourceExists(source))
{
EventLog.CreateEventSource(source, "ECCentral.Service");
}
using (EventLog errorLog = new EventLog())
{
errorLog.Source = source;
errorLog.WriteEntry(content, type);
}
}
catch (Exception ex)
{
try
{
using (EventLog log = new EventLog("Application", ".", "ECCentral.Service.Utility"))
{
log.WriteEntry(ex.ToString(), EventLogEntryType.Error);
}
}
catch
{
}
}
}
示例12: BaseWriteEntry
private void BaseWriteEntry(string message, EventLogEntryType logType, int eventId)
{
if (this.HasInitialized)
{
this.LoggerProxy.Process(new LogObject(message, logType, eventId));
}
}
示例13: Save
/// <summary>
/// Saves the specified _content.
/// </summary>
/// <param name="_content">The _content.</param>
/// <param name="_logType">Type of the _log.</param>
/// <returns>System.String.</returns>
public Result Save(string _content, EventLogEntryType _logType)
{
content = _content;
logType = _logType;
logPath = @"C:\Cube\Logs\";
return AddToFile();
}
示例14: Write
public void Write(string msg, EventLogEntryType type)
{
Console.WriteLine(msg);
// TODO: REBUILD
//_log.WriteEntry(msg, type);
}
示例15: Log
public static void Log(object sender, EventLogEntryType logType, string information) {
if (sender == null)
sender = new object();
if (!Enabled)
return;
if (!ShowAll && logType != EventLogEntryType.Error && logType != EventLogEntryType.SuccessAudit)
return;
var origin = sender.GetType().FullName;
var trace = new StringBuilder();
if (logType == EventLogEntryType.Error) {
var t = new StackTrace();
for (var i = 0; i < t.FrameCount; ++i) {
var declaringType = t.GetFrame(i).GetMethod().DeclaringType;
if (declaringType != null)
trace.Append(declaringType.FullName + "." + t.GetFrame(i).GetMethod().Name + "\r\n");
}
}
if (_log != null) {
try {
_log.WriteEntry(origin + ": " + information + "\r\n\r\nTRACE:\r\n" + trace, logType);
} catch {}
}
OnEvent?.Invoke(logType, sender, trace.ToString(), information);
}