Click here to Skip to main content
15,895,667 members
Articles / Web Development / ASP.NET

Port Writer Trace Listener for .NET Applications

Rate me:
Please Sign up or sign in to vote.
4.60/5 (11 votes)
12 Aug 2007CPOL11 min read 66.3K   1.6K   55  
A Trace Listener class writing Trace Messages to a UDP port. Also provided is a WinForm application called TraceView to view the Trace Messages sent by the Trace Listener.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PerformanceSolutions.WinForms
{
    public partial class LogFileDlg : Form
    {
        private string _FileName = string.Empty;
        private string _FileType = string.Empty;

        public string FileName
        {
            get { return _FileName; }
        }

        public string FileType
        {
            get { return _FileType; }
        }
        
        public LogFileDlg()
        {
            InitializeComponent();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            DlgOpenFile.Filter = "Csv File(*.csv)|*.csv|Xml File(*.xml)|*.xml";
            DlgOpenFile.FilterIndex = 1;
            DlgOpenFile.CheckPathExists = true;
            DlgOpenFile.RestoreDirectory = true;
            DlgOpenFile.Title = "Choose a file name";
            if (DlgOpenFile.ShowDialog() == DialogResult.OK)
            {
                txtFile.Text = DlgOpenFile.FileName;
            }
            else
            {
                return;     //Cancelled
            }

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtFile.Text.Length > 0)
            {
                _FileName = txtFile.Text;
                _FileType = FileName.Substring(FileName.Length - 4);
                if (_FileType.ToLower() != ".csv" && _FileType.ToLower() != ".xml")
                {
                    MessageBox.Show("File extension can be only .csv or .xml.", "Wrong file type...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtFile.Focus();
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please enter a file name.", "File name missing...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtFile.Focus();
                return;
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions