//写windows日志 if (!System.Diagnostics.EventLog.SourceExists("项目1")) { System.Diagnostics.EventLog.CreateEventSource("项目1", "mylog"); } System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog(); eventLog.Source = "项目1"; eventLog.WriteEntry(ex.ToString(), System.Diagnostics.EventLogEntryType.Warning); //给管理员发送邮件 System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add("23302342@qq.com");//接收人邮箱 mail.From = new System.Net.Mail.MailAddress("23423e@163.com");//发件人邮箱 mail.Subject = "程序出错了"; mail.Body = ex.ToString(); System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient("smtp.163.com");//发件人邮箱邮件服务器地址 sc.Credentials = (new System.Net.NetworkCredential("23423e", "xxxx"));//发件人邮箱名称和密码 sc.Send(mail);