本文整理汇总了C#中System.Diagnostics.EventInstance类的典型用法代码示例。如果您正苦于以下问题:C# EventInstance类的具体用法?C# EventInstance怎么用?C# EventInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventInstance类属于System.Diagnostics命名空间,在下文中一共展示了EventInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
//
// New-EventLog -source "MySource" -logname "MyLog" (cf. https://technet.microsoft.com/en-us/library/hh849768.aspx)
// Run eventvwr
// Remove-EventLog -logname "MyLog" (cf. https://technet.microsoft.com/en-us/library/hh849786.aspx)
//
WriteLine("Option A");
var eventLog = new EventLog() {Source = "Application"};
eventLog.WriteEntry("Message Option A");
WriteLine("Option B");
var eventLogB = new EventLog() {Source = "MyLog", EnableRaisingEvents = true};
var eventInstanceB = new EventInstance(0, 1);
eventLogB.WriteEvent(eventInstanceB, "Message Option B");
WriteLine("Option C");
var eventLogC = new EventLog() {Source = "MyLog"};
eventLogC.WriteEntry("Message Option C", EventLogEntryType.Error);
WriteLine("Option D");
var eventLogD = new EventLog() {Source = "MySource", EnableRaisingEvents = true};
eventLogD.WriteEntry("Message Option D", EventLogEntryType.Error);
WriteLine("Done.");
ReadLine();
}
示例2: OnEventWritten
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
var test = new EventInstance(eventData.EventId, (int)eventData.Task, EventLogEntryType.Warning);
_eventLog.WriteEvent(test, new string[] { "OpCode=1" });
_eventLog.WriteEntry("Event Occurring", EventLogEntryType.Information, eventData.EventId, (short)eventData.Task);
}
示例3: Constructor1
public void Constructor1 ()
{
EventInstance ei = null;
ei = new EventInstance (5, 10);
Assert.AreEqual (10, ei.CategoryId, "#A1");
Assert.AreEqual (5, ei.InstanceId, "#A2");
Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#A3");
ei = new EventInstance (0, 0);
Assert.AreEqual (0, ei.CategoryId, "#B1");
Assert.AreEqual (0, ei.InstanceId, "#B2");
Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#B3");
ei = new EventInstance (uint.MaxValue, ushort.MaxValue);
Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#C1");
Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#C2");
Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#C3");
}
示例4: LogProviderLifecycleEvent
internal override void LogProviderLifecycleEvent(LogContext logContext, string providerName, ProviderState newState)
{
int providerLifecycleEventId = GetProviderLifecycleEventId(newState);
if (providerLifecycleEventId != -1)
{
Hashtable mapArgs = new Hashtable();
mapArgs["ProviderName"] = providerName;
mapArgs["NewProviderState"] = newState.ToString();
FillEventArgs(mapArgs, logContext);
EventInstance entry = new EventInstance((long) providerLifecycleEventId, 6) {
EntryType = EventLogEntryType.Information
};
string eventDetail = this.GetEventDetail("ProviderLifecycleContext", mapArgs);
this.LogEvent(entry, new object[] { providerName, newState, eventDetail });
}
}
示例5: LogPipelineExecutionDetailEvent
private void LogPipelineExecutionDetailEvent(LogContext logContext, string pipelineExecutionDetail, int detailSequence, int detailTotal)
{
int num = 800;
Hashtable mapArgs = new Hashtable();
mapArgs["PipelineExecutionDetail"] = pipelineExecutionDetail;
mapArgs["DetailSequence"] = detailSequence;
mapArgs["DetailTotal"] = detailTotal;
FillEventArgs(mapArgs, logContext);
EventInstance entry = new EventInstance((long) num, 8) {
EntryType = EventLogEntryType.Information
};
string eventDetail = this.GetEventDetail("PipelineExecutionDetailContext", mapArgs);
this.LogEvent(entry, new object[] { logContext.CommandLine, eventDetail, pipelineExecutionDetail });
}
示例6: LogEngineLifecycleEvent
internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
{
int engineLifecycleEventId = GetEngineLifecycleEventId(newState);
if (engineLifecycleEventId != -1)
{
Hashtable mapArgs = new Hashtable();
mapArgs["NewEngineState"] = newState.ToString();
mapArgs["PreviousEngineState"] = previousState.ToString();
FillEventArgs(mapArgs, logContext);
EventInstance entry = new EventInstance((long) engineLifecycleEventId, 4) {
EntryType = EventLogEntryType.Information
};
string eventDetail = this.GetEventDetail("EngineLifecycleContext", mapArgs);
this.LogEvent(entry, new object[] { newState, previousState, eventDetail });
}
}
示例7: LogCommandLifecycleEvent
internal override void LogCommandLifecycleEvent(Func<LogContext> getLogContext, CommandState newState)
{
LogContext logContext = getLogContext();
int commandLifecycleEventId = GetCommandLifecycleEventId(newState);
if (commandLifecycleEventId != -1)
{
Hashtable mapArgs = new Hashtable();
mapArgs["NewCommandState"] = newState.ToString();
FillEventArgs(mapArgs, logContext);
EventInstance entry = new EventInstance((long) commandLifecycleEventId, 5) {
EntryType = EventLogEntryType.Information
};
string eventDetail = this.GetEventDetail("CommandLifecycleContext", mapArgs);
this.LogEvent(entry, new object[] { logContext.CommandName, newState, eventDetail });
}
}
示例8: WriteEvent4_Values_Null
public void WriteEvent4_Values_Null ()
{
if (EventLog.SourceExists ("monotempsource", "."))
Assert.Ignore ("Event log source 'monotempsource' should not exist.");
if (EventLog.Exists ("monologtemp", "."))
Assert.Ignore ("Event log 'monologtemp' should not exist.");
EventLog.CreateEventSource ("monotempsource", "monologtemp");
try {
byte [] data = new byte [] { 23, 54 };
EventInstance instance = new EventInstance (5, 666,
EventLogEntryType.Warning);
EventLog.WriteEvent ("monotempsource", instance, data, (object) null);
using (EventLog eventLog = new EventLog ("monologtemp", ".", "monotempsource")) {
// MSBUG: Assert.AreEqual (1, eventLog.Entries.Count, "#A1");
Assert.AreEqual ("monologtemp", eventLog.Log, "#A2");
Assert.AreEqual ("monotempsource", eventLog.Source, "#A3");
Assert.IsTrue (EventLog.Exists ("monologtemp"), "#A4");
Assert.IsTrue (EventLog.SourceExists ("monotempsource"), "#A5");
Assert.IsTrue (EventLog.SourceExists ("monologtemp"), "#A6");
Assert.AreEqual ("monologtemp", EventLog.LogNameFromSourceName ("monotempsource", "."), "#A7");
EventLogEntry entry = eventLog.Entries [eventLog.Entries.Count - 1];
Assert.IsNotNull (entry, "#B1");
Assert.IsNotNull (entry.Category, "#B2");
Assert.AreEqual ("(666)", entry.Category, "#B3");
Assert.AreEqual (666, entry.CategoryNumber, "#B4");
Assert.IsNotNull (entry.Data, "#B5");
Assert.AreEqual (data, entry.Data, "#B6");
Assert.AreEqual (EventLogEntryType.Warning, entry.EntryType, "#B7");
Assert.AreEqual (5, entry.EventID, "#B8");
Assert.AreEqual (entry.EventID, entry.InstanceId, "#B9");
Assert.IsNotNull (entry.MachineName, "#B10");
Assert.AreEqual (Environment.MachineName, entry.MachineName, "#B11");
Assert.IsNotNull (entry.ReplacementStrings, "#B12");
Assert.AreEqual (1, entry.ReplacementStrings.Length, "#B13");
Assert.AreEqual (string.Empty, entry.ReplacementStrings [0], "#B14");
Assert.IsNotNull (entry.Source, "#B15");
Assert.AreEqual ("monotempsource", entry.Source, "#B16");
Assert.IsNull (entry.UserName, "#B17");
}
} finally {
if (EventLog.Exists ("monologtemp"))
EventLog.Delete ("monologtemp");
}
}
示例9: WriteEvent4_Source_Empty
[ExpectedException (typeof (ArgumentException))] // Source property was not set before writing to the event log
public void WriteEvent4_Source_Empty ()
{
EventInstance instance = new EventInstance (5, 1,
EventLogEntryType.Information);
EventLog.WriteEvent (string.Empty, instance, new byte [0]);
}
示例10: CreateEventInstance
private EventInstance CreateEventInstance(TraceEventType severity, int id)
{
if (id > 0xffff)
{
id = 0xffff;
}
if (id < 0)
{
id = 0;
}
EventInstance instance1 = new EventInstance((long)id, 0);
if ((severity == TraceEventType.Error) || (severity == TraceEventType.Critical))
{
instance1.EntryType = EventLogEntryType.Error;
return instance1;
}
if (severity == TraceEventType.Warning)
{
instance1.EntryType = EventLogEntryType.Warning;
return instance1;
}
instance1.EntryType = EventLogEntryType.Information;
return instance1;
}
示例11: WriteEvent
public static void WriteEvent (string source, EventInstance instance, byte [] data, params object [] values)
{
using (EventLog eventLog = new EventLog ()) {
eventLog.Source = source;
eventLog.WriteEvent (instance, data, values);
}
}
示例12: TestCustomEventWriter
/// <summary>
/// The signature of this method does not change, it provides everything you need to know about the
/// log event, you may prepend fixed arguments to the arguments parameters, then simply call write.
/// BTW, since this is called from the formatter method, or from the exception constructor, you may
/// assume the current stack is the execution context for the exception. The exception's StackTrace
/// will be empty since the exception has not been thrown.
/// </summary>
public static void TestCustomEventWriter(string eventLog, string eventSource, int category, EventLogEntryType eventType, long eventId, object[] arguments, Exception error)
{
_lastLog = new EventLog(eventLog, ".", eventSource);
_lastEvent = new EventInstance(eventId, category, eventType);
_lastArgs = (string[])arguments;
}
示例13: WriteEvent2_Source_DoesNotExist
public void WriteEvent2_Source_DoesNotExist ()
{
if (EventLogImplType == NULL_IMPL)
// test cannot pass with NULL implementation
return;
if (EventLog.SourceExists ("monotempsource", "."))
Assert.Ignore ("Event log source 'monotempsource' should not exist.");
if (EventLog.SourceExists ("monoothersource", "."))
Assert.Ignore ("Event log source 'monoothersource' should not exist.");
if (EventLog.Exists ("monologtemp", "."))
Assert.Ignore ("Event log 'monologtemp' should not exist.");
EventLog.CreateEventSource ("monoothersource", "monologtemp");
try {
using (EventLog eventLog = new EventLog ("monologtemp", ".", "monotempsource")) {
byte [] data = new byte [] { 23, 54 };
EventInstance instance = new EventInstance (5, 1,
EventLogEntryType.Error);
eventLog.WriteEvent (instance, data, "replace1", "replace2");
// MSBUG: Assert.AreEqual (1, eventLog.Entries.Count, "#A1");
Assert.AreEqual ("monologtemp", eventLog.Log, "#A2");
Assert.AreEqual ("monotempsource", eventLog.Source, "#A3");
Assert.IsTrue (EventLog.Exists ("monologtemp"), "#A4");
Assert.IsTrue (EventLog.SourceExists ("monotempsource"), "#A5");
Assert.IsTrue (EventLog.SourceExists ("monologtemp"), "#A6");
Assert.AreEqual ("monologtemp", EventLog.LogNameFromSourceName ("monotempsource", "."), "#A7");
EventLogEntry entry = eventLog.Entries [eventLog.Entries.Count - 1];
Assert.IsNotNull (entry, "#B1");
Assert.IsNotNull (entry.Category, "#B2");
Assert.AreEqual ("(1)", entry.Category, "#B3");
Assert.AreEqual (1, entry.CategoryNumber, "#B4");
Assert.IsNotNull (entry.Data, "#B5");
Assert.AreEqual (data, entry.Data, "#B6");
Assert.AreEqual (EventLogEntryType.Error, entry.EntryType, "#B7");
Assert.AreEqual (5, entry.EventID, "#B8");
Assert.AreEqual (entry.EventID, entry.InstanceId, "#B9");
Assert.IsNotNull (entry.MachineName, "#B10");
Assert.AreEqual (Environment.MachineName, entry.MachineName, "#B11");
Assert.IsNotNull (entry.ReplacementStrings, "#B12");
Assert.AreEqual (2, entry.ReplacementStrings.Length, "#B13");
Assert.AreEqual ("replace1", entry.ReplacementStrings [0], "#B14");
Assert.AreEqual ("replace2", entry.ReplacementStrings [1], "#B15");
Assert.IsNotNull (entry.Source, "#B16");
Assert.AreEqual ("monotempsource", entry.Source, "#B17");
Assert.IsNull (entry.UserName, "#B18");
}
} finally {
if (EventLog.Exists ("monologtemp"))
EventLog.Delete ("monologtemp");
}
}
示例14: WriteEvent4
public void WriteEvent4 ()
{
if (EventLog.SourceExists ("monotempsource", "."))
Assert.Ignore ("Event log source 'monotempsource' should not exist.");
if (EventLog.Exists ("monologtemp", "."))
Assert.Ignore ("Event log 'monologtemp' should not exist.");
EventLog.CreateEventSource ("monotempsource", "monologtemp");
try {
byte [] data = new byte [] { 23, 54 };
EventInstance instance = new EventInstance (5, 666,
EventLogEntryType.FailureAudit);
EventLog.WriteEvent ("monotempsource", instance, data, 5, "new"
+ Environment.NewLine + "line", true, null);
using (EventLog eventLog = new EventLog ("monologtemp", ".", "monotempsource")) {
// MSBUG: Assert.AreEqual (1, eventLog.Entries.Count, "#A1");
Assert.AreEqual ("monologtemp", eventLog.Log, "#A2");
Assert.AreEqual ("monotempsource", eventLog.Source, "#A3");
Assert.IsTrue (EventLog.Exists ("monologtemp"), "#A4");
Assert.IsTrue (EventLog.SourceExists ("monotempsource"), "#A5");
Assert.IsTrue (EventLog.SourceExists ("monologtemp"), "#A6");
Assert.AreEqual ("monologtemp", EventLog.LogNameFromSourceName ("monotempsource", "."), "#A7");
EventLogEntry entry = eventLog.Entries [eventLog.Entries.Count - 1];
Assert.IsNotNull (entry, "#B1");
Assert.IsNotNull (entry.Category, "#B2");
Assert.AreEqual ("(666)", entry.Category, "#B3");
Assert.AreEqual (666, entry.CategoryNumber, "#B4");
Assert.IsNotNull (entry.Data, "#B5");
Assert.AreEqual (data, entry.Data, "#B6");
Assert.AreEqual (EventLogEntryType.FailureAudit, entry.EntryType, "#B7");
Assert.AreEqual (5, entry.EventID, "#B8");
Assert.AreEqual (entry.EventID, entry.InstanceId, "#B9");
Assert.IsNotNull (entry.MachineName, "#B10");
Assert.AreEqual (Environment.MachineName, entry.MachineName, "#B11");
Assert.IsNotNull (entry.ReplacementStrings, "#B12");
Assert.AreEqual (4, entry.ReplacementStrings.Length, "#B13");
Assert.AreEqual ("5", entry.ReplacementStrings [0], "#B14");
Assert.AreEqual ("new" + Environment.NewLine + "line", entry.ReplacementStrings [1], "#B15");
Assert.AreEqual (true.ToString (), entry.ReplacementStrings [2], "#B16");
Assert.AreEqual (string.Empty, entry.ReplacementStrings [3], "#B17");
Assert.IsNotNull (entry.Source, "#B18");
Assert.AreEqual ("monotempsource", entry.Source, "#B19");
Assert.IsNull (entry.UserName, "#B20");
EventLog.WriteEvent ("monotempsource", instance, data);
entry = eventLog.Entries [eventLog.Entries.Count - 1];
Assert.IsNotNull (entry, "#C1");
Assert.IsNotNull (entry.Category, "#C2");
Assert.AreEqual ("(666)", entry.Category, "#C3");
Assert.AreEqual (666, entry.CategoryNumber, "#C4");
Assert.IsNotNull (entry.Data, "#C5");
Assert.AreEqual (data, entry.Data, "#C6");
Assert.AreEqual (EventLogEntryType.FailureAudit, entry.EntryType, "#C7");
Assert.AreEqual (5, entry.EventID, "#C8");
Assert.AreEqual (entry.EventID, entry.InstanceId, "#C9");
Assert.IsNotNull (entry.MachineName, "#C10");
Assert.AreEqual (Environment.MachineName, entry.MachineName, "#C11");
Assert.IsNotNull (entry.ReplacementStrings, "#C12");
Assert.AreEqual (0, entry.ReplacementStrings.Length, "#C13");
Assert.IsNotNull (entry.Source, "#C14");
Assert.AreEqual ("monotempsource", entry.Source, "#C15");
Assert.IsNull (entry.UserName, "#C16");
}
} finally {
if (EventLog.Exists ("monologtemp"))
EventLog.Delete ("monologtemp");
}
}
示例15: WriteEvent
public void WriteEvent(EventInstance instance, params Object[] values) {
WriteEvent(instance, null, values);
}