EventListener.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:4k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. namespace EventListener
  8. {
  9. /// <summary>
  10. /// Summary description for Form1.
  11. /// </summary>
  12. public class EventListenerForm : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.ListBox listBoxEvents;
  15. private System.Windows.Forms.Button buttonExit;
  16. private System.Diagnostics.EventLog eventLogQuote;
  17. /// <summary>
  18. /// Required designer variable.
  19. /// </summary>
  20. private System.ComponentModel.Container components = null;
  21. public EventListenerForm()
  22. {
  23. //
  24. // Required for Windows Form Designer support
  25. //
  26. InitializeComponent();
  27. //
  28. // TODO: Add any constructor code after InitializeComponent call
  29. //
  30. }
  31. /// <summary>
  32. /// Clean up any resources being used.
  33. /// </summary>
  34. protected override void Dispose( bool disposing )
  35. {
  36. if( disposing )
  37. {
  38. if (components != null) 
  39. {
  40. components.Dispose();
  41. }
  42. }
  43. base.Dispose( disposing );
  44. }
  45. #region Windows Form Designer generated code
  46. /// <summary>
  47. /// Required method for Designer support - do not modify
  48. /// the contents of this method with the code editor.
  49. /// </summary>
  50. private void InitializeComponent()
  51. {
  52. this.listBoxEvents = new System.Windows.Forms.ListBox();
  53. this.buttonExit = new System.Windows.Forms.Button();
  54. this.eventLogQuote = new System.Diagnostics.EventLog();
  55. ((System.ComponentModel.ISupportInitialize)(this.eventLogQuote)).BeginInit();
  56. this.SuspendLayout();
  57. // 
  58. // listBoxEvents
  59. // 
  60. this.listBoxEvents.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
  61. | System.Windows.Forms.AnchorStyles.Left) 
  62. | System.Windows.Forms.AnchorStyles.Right)));
  63. this.listBoxEvents.Location = new System.Drawing.Point(8, 16);
  64. this.listBoxEvents.Name = "listBoxEvents";
  65. this.listBoxEvents.Size = new System.Drawing.Size(280, 160);
  66. this.listBoxEvents.TabIndex = 0;
  67. // 
  68. // buttonExit
  69. // 
  70. this.buttonExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  71. this.buttonExit.Location = new System.Drawing.Point(104, 192);
  72. this.buttonExit.Name = "buttonExit";
  73. this.buttonExit.TabIndex = 1;
  74. this.buttonExit.Text = "Exit";
  75. this.buttonExit.Click += new System.EventHandler(this.buttonExit_Click);
  76. // 
  77. // eventLogQuote
  78. // 
  79. this.eventLogQuote.EnableRaisingEvents = true;
  80. this.eventLogQuote.Log = "Application";
  81. this.eventLogQuote.Source = "QuoteService";
  82. this.eventLogQuote.SynchronizingObject = this;
  83. this.eventLogQuote.EntryWritten += new System.Diagnostics.EntryWrittenEventHandler(this.OnEntryWritten);
  84. // 
  85. // EventListenerForm
  86. // 
  87. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  88. this.ClientSize = new System.Drawing.Size(296, 221);
  89. this.Controls.Add(this.buttonExit);
  90. this.Controls.Add(this.listBoxEvents);
  91. this.Name = "EventListenerForm";
  92. this.Text = "Quote Service Event Listener";
  93. ((System.ComponentModel.ISupportInitialize)(this.eventLogQuote)).EndInit();
  94. this.ResumeLayout(false);
  95. }
  96. #endregion
  97. /// <summary>
  98. /// The main entry point for the application.
  99. /// </summary>
  100. [STAThread]
  101. static void Main() 
  102. {
  103. Application.Run(new EventListenerForm());
  104. }
  105. private void OnEntryWritten(object sender, System.Diagnostics.EntryWrittenEventArgs e)
  106. {
  107. DateTime time = e.Entry.TimeGenerated;
  108. string message = e.Entry.Message;
  109. listBoxEvents.Items.Add(time + " " + message);
  110. }
  111. private void buttonExit_Click(object sender, System.EventArgs e)
  112. {
  113. Application.Exit();
  114. }
  115. }
  116. }