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

推荐订阅源

F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
T
Tenable Blog
Hugging Face - Blog
Hugging Face - Blog
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
P
Proofpoint News Feed
H
Hacker News: Front Page
P
Privacy & Cybersecurity Law Blog
月光博客
月光博客
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
博客园_首页
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
Forbes - Security
Forbes - Security
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
aimingoo的专栏
aimingoo的专栏
D
Darknet – Hacking Tools, Hacker News & Cyber Security
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Hacker News - Newest:
Hacker News - Newest: "LLM"
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
O
OpenAI News
G
Google Developers Blog
Martin Fowler
Martin Fowler
罗磊的独立博客
S
SegmentFault 最新的问题
T
Tor Project blog
量子位

博客园 - 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
        }
    }
}