2014년 1월 22일 수요일

[예제]How-To Create and Use Trace Listeners[오라클/자바/빅데이터/SQL/튜닝/안드로이드/아이폰/닷넷/C#/WPF/BigData/하둡/JAVA/Spring Framework/JSP/JDBC/ASP.NET/교육/강좌]

[예제]How-To Create and Use Trace Listeners[오라클/자바/빅데이터/SQL/튜닝/안드로이드/아이폰/닷넷/C#/WPF/BigData/하둡/JAVA/Spring Framework/JSP/JDBC/ASP.NET/교육/강좌]

C#으로 만들어진 Trace용 프로그램을 올립니다. (MS예제)Trace를 HTML 페이지로 , 윈도우의 응용 프로그램 이벤트 로그로, 또는 파일로 기록을 하는 예젭니다.
실습해 보세요...

솔루션명 : How-To Create and Use Trace Listeners

--------------------------------
frmAbout.cs
--------------------------------


//Copyright (C) 2002 Microsoft Corporation
//All rights reserved.
//THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
//EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
//MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//Requires the Trial or Release version of Visual Studio .NET Professional (or greater).
using System;
using System.Windows.Forms;
public class frmAbout: System.Windows.Forms.Form
{
#region " Windows Form Designer generated code "
public frmAbout()
{
//This call is required by the Windows Form Designer.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
//Form overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
//Required by the Windows Form Designer
private System.ComponentModel.IContainer components = null;
//NOTE: The following procedure is required by the Windows Form Designer
//It can be modified using the Windows Form Designer.
//Do not modify it using the code editor.
private System.Windows.Forms.PictureBox pbIcon;
private System.Windows.Forms.Label lblTitle;
private System.Windows.Forms.Label lblVersion;
private System.Windows.Forms.Label lblDescription;
private System.Windows.Forms.Button cmdOK;
private System.Windows.Forms.Label lblCopyright;
private System.Windows.Forms.Label lblCodebase;
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmAbout));
this.pbIcon = new System.Windows.Forms.PictureBox();
this.lblTitle = new System.Windows.Forms.Label();
this.lblVersion = new System.Windows.Forms.Label();
this.lblDescription = new System.Windows.Forms.Label();
this.cmdOK = new System.Windows.Forms.Button();
this.lblCopyright = new System.Windows.Forms.Label();
this.lblCodebase = new System.Windows.Forms.Label();
this.SuspendLayout();
//
//pbIcon
//
this.pbIcon.AccessibleDescription = (string) resources.GetObject("pbIcon.AccessibleDescription");
this.pbIcon.AccessibleName = (string) resources.GetObject("pbIcon.AccessibleName");
this.pbIcon.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("pbIcon.Anchor");
this.pbIcon.BackgroundImage = (System.Drawing.Image) resources.GetObject("pbIcon.BackgroundImage");
this.pbIcon.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pbIcon.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("pbIcon.Dock");
this.pbIcon.Enabled = (bool) resources.GetObject("pbIcon.Enabled");
this.pbIcon.Font = (System.Drawing.Font) resources.GetObject("pbIcon.Font");
this.pbIcon.Image = (System.Drawing.Image) resources.GetObject("pbIcon.Image");
this.pbIcon.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("pbIcon.ImeMode");
this.pbIcon.Location = (System.Drawing.Point) resources.GetObject("pbIcon.Location");
this.pbIcon.Name = "pbIcon";
this.pbIcon.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("pbIcon.RightToLeft");
this.pbIcon.Size = (System.Drawing.Size) resources.GetObject("pbIcon.Size");
this.pbIcon.SizeMode = (System.Windows.Forms.PictureBoxSizeMode) resources.GetObject("pbIcon.SizeMode");
this.pbIcon.TabIndex = (int) resources.GetObject("pbIcon.TabIndex");
this.pbIcon.TabStop = false;
this.pbIcon.Text = resources.GetString("pbIcon.Text");
this.pbIcon.Visible = (bool) resources.GetObject("pbIcon.Visible");
//
//lblTitle
//
this.lblTitle.AccessibleDescription = (string) resources.GetObject("lblTitle.AccessibleDescription");
this.lblTitle.AccessibleName = (string) resources.GetObject("lblTitle.AccessibleName");
this.lblTitle.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("lblTitle.Anchor");
this.lblTitle.AutoSize = (bool) resources.GetObject("lblTitle.AutoSize");
this.lblTitle.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("lblTitle.Dock");
this.lblTitle.Enabled = (bool) resources.GetObject("lblTitle.Enabled");
this.lblTitle.Font = (System.Drawing.Font) resources.GetObject("lblTitle.Font");
this.lblTitle.Image = (System.Drawing.Image) resources.GetObject("lblTitle.Image");
this.lblTitle.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblTitle.ImageAlign");
this.lblTitle.ImageIndex = (int) resources.GetObject("lblTitle.ImageIndex");
this.lblTitle.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("lblTitle.ImeMode");
this.lblTitle.Location = (System.Drawing.Point) resources.GetObject("lblTitle.Location");
this.lblTitle.Name = "lblTitle";
this.lblTitle.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("lblTitle.RightToLeft");
this.lblTitle.Size = (System.Drawing.Size) resources.GetObject("lblTitle.Size");
this.lblTitle.TabIndex = (int) resources.GetObject("lblTitle.TabIndex");
this.lblTitle.Text = resources.GetString("lblTitle.Text");
this.lblTitle.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblTitle.TextAlign");
this.lblTitle.Visible = (bool) resources.GetObject("lblTitle.Visible");
//
//lblVersion
//
this.lblVersion.AccessibleDescription = (string) resources.GetObject("lblVersion.AccessibleDescription");
this.lblVersion.AccessibleName = (string) resources.GetObject("lblVersion.AccessibleName");
this.lblVersion.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("lblVersion.Anchor");
this.lblVersion.AutoSize = (bool) resources.GetObject("lblVersion.AutoSize");
this.lblVersion.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("lblVersion.Dock");
this.lblVersion.Enabled = (bool) resources.GetObject("lblVersion.Enabled");
this.lblVersion.Font = (System.Drawing.Font) resources.GetObject("lblVersion.Font");
this.lblVersion.Image = (System.Drawing.Image) resources.GetObject("lblVersion.Image");
this.lblVersion.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblVersion.ImageAlign");
this.lblVersion.ImageIndex = (int) resources.GetObject("lblVersion.ImageIndex");
this.lblVersion.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("lblVersion.ImeMode");
this.lblVersion.Location = (System.Drawing.Point) resources.GetObject("lblVersion.Location");
this.lblVersion.Name = "lblVersion";
this.lblVersion.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("lblVersion.RightToLeft");
this.lblVersion.Size = (System.Drawing.Size) resources.GetObject("lblVersion.Size");
this.lblVersion.TabIndex = (int) resources.GetObject("lblVersion.TabIndex");
this.lblVersion.Text = resources.GetString("lblVersion.Text");
this.lblVersion.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblVersion.TextAlign");
this.lblVersion.Visible = (bool) resources.GetObject("lblVersion.Visible");
//
//lblDescription
//
this.lblDescription.AccessibleDescription = (string) resources.GetObject("lblDescription.AccessibleDescription");
this.lblDescription.AccessibleName = (string) resources.GetObject("lblDescription.AccessibleName");
this.lblDescription.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("lblDescription.Anchor");
this.lblDescription.AutoSize = (bool) resources.GetObject("lblDescription.AutoSize");
this.lblDescription.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("lblDescription.Dock");
this.lblDescription.Enabled = (bool) resources.GetObject("lblDescription.Enabled");
this.lblDescription.Font = (System.Drawing.Font) resources.GetObject("lblDescription.Font");
this.lblDescription.Image = (System.Drawing.Image) resources.GetObject("lblDescription.Image");
this.lblDescription.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblDescription.ImageAlign");
this.lblDescription.ImageIndex = (int) resources.GetObject("lblDescription.ImageIndex");
this.lblDescription.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("lblDescription.ImeMode");
this.lblDescription.Location = (System.Drawing.Point) resources.GetObject("lblDescription.Location");
this.lblDescription.Name = "lblDescription";
this.lblDescription.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("lblDescription.RightToLeft");
this.lblDescription.Size = (System.Drawing.Size) resources.GetObject("lblDescription.Size");
this.lblDescription.TabIndex = (int) resources.GetObject("lblDescription.TabIndex");
this.lblDescription.Text = resources.GetString("lblDescription.Text");
this.lblDescription.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblDescription.TextAlign");
this.lblDescription.Visible = (bool) resources.GetObject("lblDescription.Visible");
//
//cmdOK
//
this.cmdOK.AccessibleDescription = (string) resources.GetObject("cmdOK.AccessibleDescription");
this.cmdOK.AccessibleName = (string) resources.GetObject("cmdOK.AccessibleName");
this.cmdOK.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("cmdOK.Anchor");
this.cmdOK.BackgroundImage = (System.Drawing.Image) resources.GetObject("cmdOK.BackgroundImage");
this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.cmdOK.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("cmdOK.Dock");
this.cmdOK.Enabled = (bool) resources.GetObject("cmdOK.Enabled");
this.cmdOK.FlatStyle = (System.Windows.Forms.FlatStyle) resources.GetObject("cmdOK.FlatStyle");
this.cmdOK.Font = (System.Drawing.Font) resources.GetObject("cmdOK.Font");
this.cmdOK.Image = (System.Drawing.Image) resources.GetObject("cmdOK.Image");
this.cmdOK.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdOK.ImageAlign");
this.cmdOK.ImageIndex = (int) resources.GetObject("cmdOK.ImageIndex");
this.cmdOK.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("cmdOK.ImeMode");
this.cmdOK.Location = (System.Drawing.Point) resources.GetObject("cmdOK.Location");
this.cmdOK.Name = "cmdOK";
this.cmdOK.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("cmdOK.RightToLeft");
this.cmdOK.Size = (System.Drawing.Size) resources.GetObject("cmdOK.Size");
this.cmdOK.TabIndex = (int) resources.GetObject("cmdOK.TabIndex");
this.cmdOK.Text = resources.GetString("cmdOK.Text");
this.cmdOK.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdOK.TextAlign");
this.cmdOK.Visible = (bool) resources.GetObject("cmdOK.Visible");
//
//lblCopyright
//
this.lblCopyright.AccessibleDescription = (string) resources.GetObject("lblCopyright.AccessibleDescription");
this.lblCopyright.AccessibleName = (string) resources.GetObject("lblCopyright.AccessibleName");
this.lblCopyright.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("lblCopyright.Anchor");
this.lblCopyright.AutoSize = (bool) resources.GetObject("lblCopyright.AutoSize");
this.lblCopyright.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("lblCopyright.Dock");
this.lblCopyright.Enabled = (bool) resources.GetObject("lblCopyright.Enabled");
this.lblCopyright.Font = (System.Drawing.Font) resources.GetObject("lblCopyright.Font");
this.lblCopyright.Image = (System.Drawing.Image) resources.GetObject("lblCopyright.Image");
this.lblCopyright.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblCopyright.ImageAlign");
this.lblCopyright.ImageIndex = (int) resources.GetObject("lblCopyright.ImageIndex");
this.lblCopyright.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("lblCopyright.ImeMode");
this.lblCopyright.Location = (System.Drawing.Point) resources.GetObject("lblCopyright.Location");
this.lblCopyright.Name = "lblCopyright";
this.lblCopyright.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("lblCopyright.RightToLeft");
this.lblCopyright.Size = (System.Drawing.Size) resources.GetObject("lblCopyright.Size");
this.lblCopyright.TabIndex = (int) resources.GetObject("lblCopyright.TabIndex");
this.lblCopyright.Text = resources.GetString("lblCopyright.Text");
this.lblCopyright.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblCopyright.TextAlign");
this.lblCopyright.Visible = (bool) resources.GetObject("lblCopyright.Visible");
//
//lblCodebase
//
this.lblCodebase.AccessibleDescription = (string) resources.GetObject("lblCodebase.AccessibleDescription");
this.lblCodebase.AccessibleName = (string) resources.GetObject("lblCodebase.AccessibleName");
this.lblCodebase.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("lblCodebase.Anchor");
this.lblCodebase.AutoSize = (bool) resources.GetObject("lblCodebase.AutoSize");
this.lblCodebase.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("lblCodebase.Dock");
this.lblCodebase.Enabled = (bool) resources.GetObject("lblCodebase.Enabled");
this.lblCodebase.Font = (System.Drawing.Font) resources.GetObject("lblCodebase.Font");
this.lblCodebase.Image = (System.Drawing.Image) resources.GetObject("lblCodebase.Image");
this.lblCodebase.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblCodebase.ImageAlign");
this.lblCodebase.ImageIndex = (int) resources.GetObject("lblCodebase.ImageIndex");
this.lblCodebase.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("lblCodebase.ImeMode");
this.lblCodebase.Location = (System.Drawing.Point) resources.GetObject("lblCodebase.Location");
this.lblCodebase.Name = "lblCodebase";
this.lblCodebase.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("lblCodebase.RightToLeft");
this.lblCodebase.Size = (System.Drawing.Size) resources.GetObject("lblCodebase.Size");
this.lblCodebase.TabIndex = (int) resources.GetObject("lblCodebase.TabIndex");
this.lblCodebase.Text = resources.GetString("lblCodebase.Text");
this.lblCodebase.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("lblCodebase.TextAlign");
this.lblCodebase.Visible = (bool) resources.GetObject("lblCodebase.Visible");
//
//frmAbout
//
this.AcceptButton = this.cmdOK;
this.AccessibleDescription = (string) resources.GetObject("$this.AccessibleDescription");
this.AccessibleName = (string) resources.GetObject("$this.AccessibleName");
this.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("$this.Anchor");
this.AutoScaleBaseSize = (System.Drawing.Size) resources.GetObject("$this.AutoScaleBaseSize");
this.AutoScroll = (bool) resources.GetObject("$this.AutoScroll");
this.AutoScrollMargin = (System.Drawing.Size) resources.GetObject("$this.AutoScrollMargin");
this.AutoScrollMinSize = (System.Drawing.Size) resources.GetObject("$this.AutoScrollMinSize");
this.BackgroundImage = (System.Drawing.Image) resources.GetObject("$this.BackgroundImage");
this.CancelButton = this.cmdOK;
this.ClientSize = (System.Drawing.Size) resources.GetObject("$this.ClientSize");
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.lblCodebase, this.lblCopyright, this.cmdOK, this.lblDescription, this.lblVersion, this.lblTitle, this.pbIcon});
this.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("$this.Dock");
this.Enabled = (bool) resources.GetObject("$this.Enabled");
this.Font = (System.Drawing.Font) resources.GetObject("$this.Font");
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = (System.Drawing.Icon) resources.GetObject("$this.Icon");
this.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("$this.ImeMode");
this.Location = (System.Drawing.Point) resources.GetObject("$this.Location");
this.MaximizeBox = false;
this.MaximumSize = (System.Drawing.Size) resources.GetObject("$this.MaximumSize");
this.MinimizeBox = false;
this.MinimumSize = (System.Drawing.Size) resources.GetObject("$this.MinimumSize");
this.Name = "frmAbout";
this.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("$this.RightToLeft");
this.ShowInTaskbar = false;
this.StartPosition = (System.Windows.Forms.FormStartPosition) resources.GetObject("$this.StartPosition");
this.Text = resources.GetString("$this.Text");
this.Visible = (bool) resources.GetObject("$this.Visible");
this.ResumeLayout(false);
this.Load += new System.EventHandler(frmAbout_Load);
}
#endregion
// Note: Because this form is opened by frmMain using the ShowDialog command, we simply set the
// DialogResult property of cmdOK to OK which causes the form to close when clicked.
private void frmAbout_Load(object sender, System.EventArgs e)
{
try
{
// Set this Form's Text + Icon properties by using values from the parent form
this.Text = "About " + this.Owner.Text;
this.Icon = this.Owner.Icon;
// Set this Form's Picture Box's image using the parent's icon
// However, we need to convert it to a Bitmap since the Picture Box Control
// will not accept a raw Icon.
this.pbIcon.Image = this.Owner.Icon.ToBitmap();
// Set the labels identitying the Title, Version, and Description by
// reading Assembly meta-data originally entered in the AssemblyInfo.cs file
// using the AssemblyInfo class defined in the same file
AssemblyInfo ainfo = new AssemblyInfo();
this.lblTitle.Text = ainfo.Title;
this.lblVersion.Text = string.Format("Version {0}", ainfo.Version);
this.lblCopyright.Text = ainfo.Copyright;
this.lblDescription.Text = ainfo.Description;
this.lblCodebase.Text = ainfo.CodeBase;
}
catch(System.Exception exp)
{
// This catch will trap any unexpected error.
MessageBox.Show(exp.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
}


-----------------------------
frmMain.cs
-----------------------------


//Copyright (C) 2002 Microsoft Corporation
//All rights reserved.
//THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
//EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
//MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//Requires the Trial or Release version of Visual Studio .NET Professional
//(or greater).
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
public class frmMain: System.Windows.Forms.Form
{
#region " Windows Form Designer generated code "
public frmMain()
{
//This call is required by the Windows Form Designer.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
// So that we only need to set the title of the application once,
// we use the AssemblyInfo class (defined in the AssemblyInfo.cs file)
// to read the AssemblyTitle attribute.
AssemblyInfo ainfo = new AssemblyInfo();
this.Text = ainfo.Title;
this.mnuAbout.Text = string.Format("&About {0} ...", ainfo.Title);
}
//Form overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
//Required by the Windows Form Designer
private System.ComponentModel.IContainer components = null;
//NOTE: The following procedure is required by the Windows Form Designer
//It can be modified using the Windows Form Designer.
//Do not modify it using the code editor.
private System.Windows.Forms.MainMenu mnuMain;
private System.Windows.Forms.MenuItem mnuFile;
private System.Windows.Forms.MenuItem mnuExit;
private System.Windows.Forms.MenuItem mnuHelp;
private System.Windows.Forms.MenuItem mnuAbout;
private System.Windows.Forms.Button cmdTraceToOutput;
private System.Windows.Forms.Button cmdTraceToEventLog;
private System.Windows.Forms.Button cmdTraceToFile;
private System.Windows.Forms.Button cmdTraceToHTML;
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
this.mnuMain = new System.Windows.Forms.MainMenu();
this.mnuFile = new System.Windows.Forms.MenuItem();
this.mnuExit = new System.Windows.Forms.MenuItem();
this.mnuHelp = new System.Windows.Forms.MenuItem();
this.mnuAbout = new System.Windows.Forms.MenuItem();
this.cmdTraceToOutput = new System.Windows.Forms.Button();
this.cmdTraceToEventLog = new System.Windows.Forms.Button();
this.cmdTraceToFile = new System.Windows.Forms.Button();
this.cmdTraceToHTML = new System.Windows.Forms.Button();
this.SuspendLayout();
//
//mnuMain
//
this.mnuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {this.mnuFile, this.mnuHelp});
this.mnuMain.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("mnuMain.RightToLeft");
//
//mnuFile
//
this.mnuFile.Enabled = (bool) resources.GetObject("mnuFile.Enabled");
this.mnuFile.Index = 0;
this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {this.mnuExit});
this.mnuFile.Shortcut = (System.Windows.Forms.Shortcut) resources.GetObject("mnuFile.Shortcut");
this.mnuFile.ShowShortcut = (bool) resources.GetObject("mnuFile.ShowShortcut");
this.mnuFile.Text = resources.GetString("mnuFile.Text");
this.mnuFile.Visible = (bool) resources.GetObject("mnuFile.Visible");
//
//mnuExit
//
this.mnuExit.Enabled = (bool) resources.GetObject("mnuExit.Enabled");
this.mnuExit.Index = 0;
this.mnuExit.Shortcut = (System.Windows.Forms.Shortcut) resources.GetObject("mnuExit.Shortcut");
this.mnuExit.ShowShortcut = (bool) resources.GetObject("mnuExit.ShowShortcut");
this.mnuExit.Text = resources.GetString("mnuExit.Text");
this.mnuExit.Visible = (bool) resources.GetObject("mnuExit.Visible");
//
//mnuHelp
//
this.mnuHelp.Enabled = (bool) resources.GetObject("mnuHelp.Enabled");
this.mnuHelp.Index = 1;
this.mnuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {this.mnuAbout});
this.mnuHelp.Shortcut = (System.Windows.Forms.Shortcut) resources.GetObject("mnuHelp.Shortcut");
this.mnuHelp.ShowShortcut = (bool) resources.GetObject("mnuHelp.ShowShortcut");
this.mnuHelp.Text = resources.GetString("mnuHelp.Text");
this.mnuHelp.Visible = (bool) resources.GetObject("mnuHelp.Visible");
//
//mnuAbout
//
this.mnuAbout.Enabled = (bool) resources.GetObject("mnuAbout.Enabled");
this.mnuAbout.Index = 0;
this.mnuAbout.Shortcut = (System.Windows.Forms.Shortcut) resources.GetObject("mnuAbout.Shortcut");
this.mnuAbout.ShowShortcut = (bool) resources.GetObject("mnuAbout.ShowShortcut");
this.mnuAbout.Text = resources.GetString("mnuAbout.Text");
this.mnuAbout.Visible = (bool) resources.GetObject("mnuAbout.Visible");
//
//cmdTraceToOutput
//
this.cmdTraceToOutput.AccessibleDescription = resources.GetString("cmdTraceToOutput.AccessibleDescription");
this.cmdTraceToOutput.AccessibleName = resources.GetString("cmdTraceToOutput.AccessibleName");
this.cmdTraceToOutput.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("cmdTraceToOutput.Anchor");
this.cmdTraceToOutput.BackgroundImage = (System.Drawing.Image) resources.GetObject("cmdTraceToOutput.BackgroundImage");
this.cmdTraceToOutput.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("cmdTraceToOutput.Dock");
this.cmdTraceToOutput.Enabled = (bool) resources.GetObject("cmdTraceToOutput.Enabled");
this.cmdTraceToOutput.FlatStyle = (System.Windows.Forms.FlatStyle) resources.GetObject("cmdTraceToOutput.FlatStyle");
this.cmdTraceToOutput.Font = (System.Drawing.Font) resources.GetObject("cmdTraceToOutput.Font");
this.cmdTraceToOutput.Image = (System.Drawing.Image) resources.GetObject("cmdTraceToOutput.Image");
this.cmdTraceToOutput.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdTraceToOutput.ImageAlign");
this.cmdTraceToOutput.ImageIndex = (int) resources.GetObject("cmdTraceToOutput.ImageIndex");
this.cmdTraceToOutput.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("cmdTraceToOutput.ImeMode");
this.cmdTraceToOutput.Location = (System.Drawing.Point) resources.GetObject("cmdTraceToOutput.Location");
this.cmdTraceToOutput.Name = "cmdTraceToOutput";
this.cmdTraceToOutput.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("cmdTraceToOutput.RightToLeft");
this.cmdTraceToOutput.Size = (System.Drawing.Size) resources.GetObject("cmdTraceToOutput.Size");
this.cmdTraceToOutput.TabIndex = (int) resources.GetObject("cmdTraceToOutput.TabIndex");
this.cmdTraceToOutput.Text = resources.GetString("cmdTraceToOutput.Text");
this.cmdTraceToOutput.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdTraceToOutput.TextAlign");
this.cmdTraceToOutput.Visible = (bool) resources.GetObject("cmdTraceToOutput.Visible");
//
//cmdTraceToEventLog
//
this.cmdTraceToEventLog.AccessibleDescription = resources.GetString("cmdTraceToEventLog.AccessibleDescription");
this.cmdTraceToEventLog.AccessibleName = resources.GetString("cmdTraceToEventLog.AccessibleName");
this.cmdTraceToEventLog.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("cmdTraceToEventLog.Anchor");
this.cmdTraceToEventLog.BackgroundImage = (System.Drawing.Image) resources.GetObject("cmdTraceToEventLog.BackgroundImage");
this.cmdTraceToEventLog.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("cmdTraceToEventLog.Dock");
this.cmdTraceToEventLog.Enabled = (bool) resources.GetObject("cmdTraceToEventLog.Enabled");
this.cmdTraceToEventLog.FlatStyle = (System.Windows.Forms.FlatStyle) resources.GetObject("cmdTraceToEventLog.FlatStyle");
this.cmdTraceToEventLog.Font = (System.Drawing.Font) resources.GetObject("cmdTraceToEventLog.Font");
this.cmdTraceToEventLog.Image = (System.Drawing.Image) resources.GetObject("cmdTraceToEventLog.Image");
this.cmdTraceToEventLog.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdTraceToEventLog.ImageAlign");
this.cmdTraceToEventLog.ImageIndex = (int) resources.GetObject("cmdTraceToEventLog.ImageIndex");
this.cmdTraceToEventLog.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("cmdTraceToEventLog.ImeMode");
this.cmdTraceToEventLog.Location = (System.Drawing.Point) resources.GetObject("cmdTraceToEventLog.Location");
this.cmdTraceToEventLog.Name = "cmdTraceToEventLog";
this.cmdTraceToEventLog.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("cmdTraceToEventLog.RightToLeft");
this.cmdTraceToEventLog.Size = (System.Drawing.Size) resources.GetObject("cmdTraceToEventLog.Size");
this.cmdTraceToEventLog.TabIndex = (int) resources.GetObject("cmdTraceToEventLog.TabIndex");
this.cmdTraceToEventLog.Text = resources.GetString("cmdTraceToEventLog.Text");
this.cmdTraceToEventLog.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdTraceToEventLog.TextAlign");
this.cmdTraceToEventLog.Visible = (bool) resources.GetObject("cmdTraceToEventLog.Visible");
//
//cmdTraceToFile
//
this.cmdTraceToFile.AccessibleDescription = resources.GetString("cmdTraceToFile.AccessibleDescription");
this.cmdTraceToFile.AccessibleName = resources.GetString("cmdTraceToFile.AccessibleName");
this.cmdTraceToFile.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("cmdTraceToFile.Anchor");
this.cmdTraceToFile.BackgroundImage = (System.Drawing.Image) resources.GetObject("cmdTraceToFile.BackgroundImage");
this.cmdTraceToFile.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("cmdTraceToFile.Dock");
this.cmdTraceToFile.Enabled = (bool) resources.GetObject("cmdTraceToFile.Enabled");
this.cmdTraceToFile.FlatStyle = (System.Windows.Forms.FlatStyle) resources.GetObject("cmdTraceToFile.FlatStyle");
this.cmdTraceToFile.Font = (System.Drawing.Font) resources.GetObject("cmdTraceToFile.Font");
this.cmdTraceToFile.Image = (System.Drawing.Image) resources.GetObject("cmdTraceToFile.Image");
this.cmdTraceToFile.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdTraceToFile.ImageAlign");
this.cmdTraceToFile.ImageIndex = (int) resources.GetObject("cmdTraceToFile.ImageIndex");
this.cmdTraceToFile.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("cmdTraceToFile.ImeMode");
this.cmdTraceToFile.Location = (System.Drawing.Point) resources.GetObject("cmdTraceToFile.Location");
this.cmdTraceToFile.Name = "cmdTraceToFile";
this.cmdTraceToFile.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("cmdTraceToFile.RightToLeft");
this.cmdTraceToFile.Size = (System.Drawing.Size) resources.GetObject("cmdTraceToFile.Size");
this.cmdTraceToFile.TabIndex = (int) resources.GetObject("cmdTraceToFile.TabIndex");
this.cmdTraceToFile.Text = resources.GetString("cmdTraceToFile.Text");
this.cmdTraceToFile.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdTraceToFile.TextAlign");
this.cmdTraceToFile.Visible = (bool) resources.GetObject("cmdTraceToFile.Visible");
//
//cmdTraceToHTML
//
this.cmdTraceToHTML.AccessibleDescription = resources.GetString("cmdTraceToHTML.AccessibleDescription");
this.cmdTraceToHTML.AccessibleName = resources.GetString("cmdTraceToHTML.AccessibleName");
this.cmdTraceToHTML.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("cmdTraceToHTML.Anchor");
this.cmdTraceToHTML.BackgroundImage = (System.Drawing.Image) resources.GetObject("cmdTraceToHTML.BackgroundImage");
this.cmdTraceToHTML.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("cmdTraceToHTML.Dock");
this.cmdTraceToHTML.Enabled = (bool) resources.GetObject("cmdTraceToHTML.Enabled");
this.cmdTraceToHTML.FlatStyle = (System.Windows.Forms.FlatStyle) resources.GetObject("cmdTraceToHTML.FlatStyle");
this.cmdTraceToHTML.Font = (System.Drawing.Font) resources.GetObject("cmdTraceToHTML.Font");
this.cmdTraceToHTML.Image = (System.Drawing.Image) resources.GetObject("cmdTraceToHTML.Image");
this.cmdTraceToHTML.ImageAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdTraceToHTML.ImageAlign");
this.cmdTraceToHTML.ImageIndex = (int) resources.GetObject("cmdTraceToHTML.ImageIndex");
this.cmdTraceToHTML.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("cmdTraceToHTML.ImeMode");
this.cmdTraceToHTML.Location = (System.Drawing.Point) resources.GetObject("cmdTraceToHTML.Location");
this.cmdTraceToHTML.Name = "cmdTraceToHTML";
this.cmdTraceToHTML.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("cmdTraceToHTML.RightToLeft");
this.cmdTraceToHTML.Size = (System.Drawing.Size) resources.GetObject("cmdTraceToHTML.Size");
this.cmdTraceToHTML.TabIndex = (int) resources.GetObject("cmdTraceToHTML.TabIndex");
this.cmdTraceToHTML.Text = resources.GetString("cmdTraceToHTML.Text");
this.cmdTraceToHTML.TextAlign = (System.Drawing.ContentAlignment) resources.GetObject("cmdTraceToHTML.TextAlign");
this.cmdTraceToHTML.Visible = (bool) resources.GetObject("cmdTraceToHTML.Visible");
//
//frmMain
//
this.AccessibleDescription = (string) resources.GetObject("$this.AccessibleDescription");
this.AccessibleName = (string) resources.GetObject("$this.AccessibleName");
this.Anchor = (System.Windows.Forms.AnchorStyles) resources.GetObject("$this.Anchor");
this.AutoScaleBaseSize = (System.Drawing.Size) resources.GetObject("$this.AutoScaleBaseSize");
this.AutoScroll = (bool) resources.GetObject("$this.AutoScroll");
this.AutoScrollMargin = (System.Drawing.Size) resources.GetObject("$this.AutoScrollMargin");
this.AutoScrollMinSize = (System.Drawing.Size) resources.GetObject("$this.AutoScrollMinSize");
this.BackgroundImage = (System.Drawing.Image) resources.GetObject("$this.BackgroundImage");
this.ClientSize = (System.Drawing.Size) resources.GetObject("$this.ClientSize");
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.cmdTraceToHTML, this.cmdTraceToFile, this.cmdTraceToEventLog, this.cmdTraceToOutput});
this.Dock = (System.Windows.Forms.DockStyle) resources.GetObject("$this.Dock");
this.Enabled = (bool) resources.GetObject("$this.Enabled");
this.Font = (System.Drawing.Font) resources.GetObject("$this.Font");
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = (System.Drawing.Icon) resources.GetObject("$this.Icon");
this.ImeMode = (System.Windows.Forms.ImeMode) resources.GetObject("$this.ImeMode");
this.Location = (System.Drawing.Point) resources.GetObject("$this.Location");
this.MaximizeBox = false;
this.MaximumSize = (System.Drawing.Size) resources.GetObject("$this.MaximumSize");
this.Menu = this.mnuMain;
this.MinimumSize = (System.Drawing.Size) resources.GetObject("$this.MinimumSize");
this.Name = "frmMain";
this.RightToLeft = (System.Windows.Forms.RightToLeft) resources.GetObject("$this.RightToLeft");
this.StartPosition = (System.Windows.Forms.FormStartPosition) resources.GetObject("$this.StartPosition");
this.Text = resources.GetString("$this.Text");
this.Visible = (bool) resources.GetObject("$this.Visible");
this.ResumeLayout(false);
this.cmdTraceToEventLog.Click += new EventHandler(cmdTraceToEventLog_Click);
this.cmdTraceToFile.Click += new EventHandler(cmdTraceToFile_Click);
this.cmdTraceToHTML.Click += new EventHandler(cmdTraceToHTML_Click);
this.cmdTraceToOutput.Click += new EventHandler(cmdTraceToOutput_Click);
this.mnuExit.Click += new EventHandler(mnuExit_Click);
this.mnuAbout.Click += new EventHandler(mnuAbout_Click);
}
#endregion
///



/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new frmMain());
}


#region " Standard Menu Code "
// This code simply shows the About form.
private void mnuAbout_Click(object sender, System.EventArgs e)
{
// Open the About form in Dialog Mode
frmAbout frm = new frmAbout();
frm.ShowDialog(this);
frm.Dispose();
}
// This code will close the form.
private void mnuExit_Click(object sender, System.EventArgs e)
{
// Close the current form
this.Close();
}
#endregion
private void cmdTraceToEventLog_Click(object sender, System.EventArgs e)
{
// This void demonstrates how to create and add a trace
// listener that sends messages to the application
// event log. This should be used sparingly due to the
// resources it uses to write to the event log.
// Create an EventLog instance and assign it a source.
EventLog myLog = new EventLog();
myLog.Source = this.Text;
// Create a trace listener for the application event log.
EventLogTraceListener tlEventLog = new EventLogTraceListener(myLog);
Trace.Listeners.Clear();
// Add the event log trace listener to the collection.
Trace.Listeners.Add(tlEventLog);
// Write output to the event log.
Trace.WriteLine("This is a test of event log tracing");
}
private void cmdTraceToFile_Click(object sender, System.EventArgs e)
{
// This sub shows how to add a trace listener that sends
// the trace output to a text file called TraceOutput.txt.
// This file is created in the same folder the EXE which
// is usually the bin folder where the project is saved.
// Create a file for output named TraceOutput.txt.
System.IO.Stream traceFile = File.Create("TraceOutput.txt");
// some variables to display in trace output
string ProductType = "Computer";
int Price = 2000;
// Create an instance of the text writer trace listener to
// output to a text file
TextWriterTraceListener tlTextFile = new TextWriterTraceListener(traceFile);
// Clear the listeners collection
Trace.Listeners.Clear();
Trace.Listeners.Add(tlTextFile);
// WriteLine will output a mesaage and will issue a carriage
// return line feed
Trace.WriteLine("****** Trace Output to File ******");
Trace.WriteLine("Trace output for " + this.Text);
Trace.WriteLine(string.Empty);
// This will indent all lines until Unindent is called
Trace.Indent();
Trace.WriteLine("This line is indented");
Trace.WriteLine("Product Type = " + ProductType);
Trace.WriteLine("Price = $" + Price);
// WriteLineif is a condition way of sending messages to the trace
// when the first argument evaluates to true
Trace.WriteLineIf(Price > 1800, "Price > $1800");
Trace.Unindent();
// Flush and close the output.
tlTextFile.Flush();
tlTextFile.Close();
// Show text file output
System.Diagnostics.Process.Start("Notepad.exe", "TraceOutput.txt");
}
private void cmdTraceToHTML_Click(object sender, System.EventArgs e)
{
// This sub shows how to add a custom trace listener that
// sends the trace output to a HTML file called TraceOutputHTML.htm
// This file is created in the same folder your EXE which
// is usually the bin folder under where the project is saved.
// Create a file for output named TraceOutputHTML.htm
System.IO.Stream traceFile = File.Create("TraceOutputHTML.htm");

// some variables to display in trace output
string ProductType = "Computer";
int Price = 2000;

// Create an instance of the text writer trace listener to
// output to a text file
HTMLTraceListener tlHTMLFile = new HTMLTraceListener(traceFile);
tlHTMLFile.WriteHeader("HTML Trace Output Example for " + this.Text);
// Clear the listeners collection
Trace.Listeners.Clear();
Trace.Listeners.Add(tlHTMLFile);
// This will indent all lines until Unindent is called
Trace.Indent();
Trace.WriteLine("This line is indented");
Trace.Unindent();
Trace.WriteLine("Product Type = " + ProductType);
Trace.WriteLine("Price = $" + Price);
// WriteLineif is a condition way of sending messages to the trace
// when the first argument evaluates to true
Trace.WriteLineIf(Price > 1800, "Price > $1800");
// Flush and close the output.
tlHTMLFile.Flush();
tlHTMLFile.Close();
// Launch default browser to show file output
System.Diagnostics.Process.Start("TraceOutputHTML.htm");
}
private void cmdTraceToOutput_Click(object sender, System.EventArgs e)
{
// This sub shows how to use the default trace listener that
// sends the trace output to the Output window in the IDE.
// It also shows how to readd the default trace listener if the
// trace listeners collection has been cleared. The default trace
// listener by default is added to the trace listeners collection.
// some variables to display in trace output
string ProductType = "Computer";
int Price = 2000;

// Create instance of the default trace listener
DefaultTraceListener tlDefault = new DefaultTraceListener();
// Clear all trace listeners from the collection
Trace.Listeners.Clear();
// Add the default listener to the collection
Trace.Listeners.Add(tlDefault);
// WriteLine will output a mesaage and will issue a
// carriage return line feed
Trace.WriteLine("****** Trace OutPut Start ******");
Trace.WriteLine("Output window trace information");
// This will indent all lines until Unindent is called
Trace.Indent();
Trace.WriteLine("This line is indented");
Trace.WriteLine("Product Type = " + ProductType);
Trace.WriteLine("Price = $" + Price);
// WriteLineif is a condition way of sending messages to the trace
// when the first argument evaluates to true
Trace.WriteLineIf(Price > 1800, "Price > $1800");
Trace.Unindent();
Trace.WriteLine("****** Trace Output End ******");
}
}

------------------------------
HTMLTraceListener.cs
-------------------------------
using System;
using System.IO;
// This class was created to output trace messages to an HTML file using tags
public class HTMLTraceListener: System.Diagnostics.TextWriterTraceListener
{
// Use constructor from TextWriterTraceListener to write to a stream
public HTMLTraceListener(Stream stream): base(stream) {}
public void WriteHeader(string Title)
{
// new method to add a title to the top of the HTML document
Writer.WriteLine("");
Writer.WriteLine("");
Writer.WriteLine("");
Writer.WriteLine("

" + Title + "

");
Writer.WriteLine("


");
}

protected override void WriteIndent()
{
// Override WriteIndent to handle indention in an HTML document
// using for a space
if (IndentLevel > 0)
{
for(int i = 1; i < IndentLevel; i++)>
{
for(int j = 1; j < IndentSize; j++)>
{
Writer.Write(" ");
}
}
}
}
public override void WriteLine(string message)
{
// Override WriteLine Method to add tags to output message
Writer.Write("" + DateTime.Now.ToString() + " - ");
if (NeedIndent)
{
WriteIndent();
}

Writer.WriteLine(message + "
");
}
}
 

  • 자바
  • 오라클/빅데이터
  • 아이폰/안드로이드
  • 닷넷/WPF
  • 표준웹/HTML5
  • 채용/취업무료교육
  • 초보자코스

  • 댓글 없음:

    댓글 쓰기