惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
U
Unit 42
W
WeLiveSecurity
博客园 - Franky
Recent Announcements
Recent Announcements
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
月光博客
月光博客
The Cloudflare Blog
Spread Privacy
Spread Privacy
腾讯CDC
P
Privacy International News Feed
N
News and Events Feed by Topic
AWS News Blog
AWS News Blog
NISL@THU
NISL@THU
T
Troy Hunt's Blog
小众软件
小众软件
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Microsoft Security Blog
Microsoft Security Blog
L
Lohrmann on Cybersecurity
Webroot Blog
Webroot Blog
Y
Y Combinator Blog
量子位
P
Palo Alto Networks Blog
N
News and Events Feed by Topic
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
IT之家
IT之家
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
云风的 BLOG
云风的 BLOG
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
G
Google Developers Blog
S
Secure Thoughts

博客园 - kuning的程序博客

第一章 第二课 Using Resources 第一章 第一课 Using WPF Control Cmd,powershell 参考 百度WSUS 我也转关于软件测试的文章 了解WMI 英文面试题 据说是微软面试哦 算法 之 万年历 算法 之 哥德巴赫猜想 - kuning的程序博客 C# 理论学习 之 面向对象设计 C# 理论学习 之 类、组,名称空间 C#深入学习 之 委托和事件 C#数据结构-排序之快速排序法 .Net本地化资源 PHP之安装篇 Sql Server中的行列互换 再叙2005Web控件(一) - kuning的程序博客 - 博客园 Poket PC 与 sqlserver2000(以上) RDA 方案
C# 深入学习 之 Winform记录日志
kuning的程序博客 · 2010-03-21 · via 博客园 - kuning的程序博客
using System;
using System.Windows.Forms;
using ST = System.Threading;
using SWF = System.Windows.Forms;
using T = System.Diagnostics.Trace;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(OnAppException);
            Application.ThreadExit += new EventHandler(OnAppExit);
            string logFile = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Applog.txt");
            System.IO.TextWriter log = new System.IO.StreamWriter(logFile);

            if (true)
            {
                System.Diagnostics.TextWriterTraceListener logger;
                logger = new System.Diagnostics.TextWriterTraceListener(log);
                System.Diagnostics.Trace.Listeners.Add(logger);
                System.Diagnostics.Trace.WriteLine("App starting:" + DateTime.Now);
 
            }
            Application.Run(new Form1());
        }

        /// <summary>
        /// Generic exception handler for application.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnAppException(object sender, ST.ThreadExceptionEventArgs e)
        {
            Exception ex;
            ex = e.Exception;

            // inform user...
            SWF.MessageBox.Show("Halting due to error: " + ex.Message, "Bank Customer App", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

            // log it (the entire exception chain)...
            T.WriteLine("Generic Application Exception Handler:");
            while (ex != null)
            {
                T.WriteLine(ex.GetType().FullName);
                T.Indent();
                T.WriteLine("Msg: " + ex.Message);
                T.WriteLine("Trace: " + ex.StackTrace);
                T.Unindent();
                T.Flush();

                ex = ex.InnerException;
            }//while

            // halt app
            T.Close();
            SWF.Application.Exit();
        }

        /// <summary>
        /// Called during normal application termination.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnAppExit(object sender, System.EventArgs e)
        {
            T.Close();  // close trace file
        }
    }
}