我电脑升级成 Window 2008 R2 后, 一个企业服务的项目出现如下错误:未找到源,但未能搜索某些或全部事件日志。不可访问的日志: Security。
在这个企业服务中,当有错误发生时候,会把错误记录到Windows的事件日志中,这部分的代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace CSDN.Community.TopicListDataCenter
{
/// <summary>
/// </summary>记录到事件日志
///
public class MyLog
{
/// <summary>
/// </summary>把异常写入日志
///
///
///
/// public static void Writer(string group, string name, Exception ex)
{
if (GACGlobals.IsNullorEmpty(group))
{
MyLog.Writer(ex);
return;
}
StringBuilder text = new StringBuilder();
if (!GACGlobals.IsNullorEmpty(name))
text.AppendLine(name);
text.AppendFormat("{0} : {1}", DateTime.Now.ToString("u"), Environment.NewLine);
if (ex != null)
{
text.AppendFormat("\t Type: {0}{1}", ex.GetType().Name, Environment.NewLine);
text.AppendFormat("\tMessage: {0}{1}", ex.Message, Environment.NewLine);
text.AppendFormat("\t Source: {0}{1}", ex.Source, Environment.NewLine);
text.AppendFormat("\t Stack: {0}{1}", ex.StackTrace, Environment.NewLine);
while (ex.InnerException != null)
{
text.AppendFormat("\t Type: {0}{1}", ex.InnerException.GetType().Name, Environment.NewLine);
text.AppendFormat("\tMessage: {0}{1}", ex.InnerException.Message, Environment.NewLine);
text.AppendFormat("\t Source: {0}{1}", ex.InnerException.Source, Environment.NewLine);
text.AppendFormat("\t Stack: {0}{1}", ex.InnerException.StackTrace, Environment.NewLine);
ex = ex.InnerException;
}
}
text.AppendLine("***********************");
// 写事件日志
if (!EventLog.SourceExists(group))
{
EventLog.CreateEventSource(group, "Application");
}
EventLog logEntry = new EventLog();
logEntry.Source = group;
logEntry.WriteEntry(text.ToString(), EventLogEntryType.Error);
logEntry.Close();
}
/// <summary>
/// </summary>把异常写入时间日志
///
/// public static void Writer(Exception ex)
{
StringBuilder text = new StringBuilder();
text.AppendFormat("{0} : {1}", DateTime.Now.ToString("u"), Environment.NewLine);
if (ex != null)
{
text.AppendFormat("\t Type: {0}{1}", ex.GetType().Name, Environment.NewLine);
text.AppendFormat("\tMessage: {0}{1}", ex.Message, Environment.NewLine);
text.AppendFormat("\t Source: {0}{1}", ex.Source, Environment.NewLine);
text.AppendFormat("\t Stack: {0}{1}", ex.StackTrace, Environment.NewLine);
while (ex.InnerException != null)
{
text.AppendFormat("\t Type: {0}{1}", ex.InnerException.GetType().Name, Environment.NewLine);
text.AppendFormat("\tMessage: {0}{1}", ex.InnerException.Message, Environment.NewLine);
text.AppendFormat("\t Source: {0}{1}", ex.InnerException.Source, Environment.NewLine);
text.AppendFormat("\t Stack: {0}{1}", ex.InnerException.StackTrace, Environment.NewLine);
ex = ex.InnerException;
}
}
text.AppendLine("***********************");
// 写事件日志
if (!EventLog.SourceExists(".NET Runtime"))
{
EventLog.CreateEventSource(".NET Runtime", "Application");
}
EventLog logEntry = new EventLog();
logEntry.Source = ".NET Runtime";
logEntry.WriteEntry(text.ToString(), EventLogEntryType.Error);
logEntry.Close();
}
}
}
显然,默认情况下,是因为无权执行 EventLog.CreateEventSource( 导致的问题,
而这个问题,以前在 Win2008, Win2003 上都是没有问题的。
以前我这里的设置如下图:
在Win2008 R2 中如果要解决这个问题,则需要 打开 应用软件限制策略,并把它设置成“不受限”即可。这样就有权限执行 EventLog.CreateEventSource( 这行代码了。如下图:
或者,手工在注册表中提前添加 EventLog.CreateEventSource( 用到的一些日志分类。
即:在注册表里预先建好日志项(运行regedit,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog
右键单击新建-->项)
在上述设置选项中,除了不受限,不允许外,还有一个名为”基本用户”的策略,”基本用户”这条策略的含义是,除了通过其他规则明确指定的软件外,其他所有软件都只能以一般用户的身份运行(也就是说,不能以管理员的身份运行)。
参考资料:
C# 编写的Windows serice程序. 安装时出现异常
http://topic.csdn.net/u/20080129/16/479cedb2-d848-422a-a53a-5402e4384b20.html
COM+ 应用程序 属性页:“安全”选项卡
http://technet.microsoft.com/zh-cn/library/dd145616.aspx
活用软件限制策略
http://www.xieyidian.com/?p=266
分享到:
相关推荐
组策略管理在windows域管理中占有重要地位,本身也不是新的内容了。但微软在Windows2008中终于集成了一个非常好用的组策略管理工具——组策略管理控制台。注意:2008 r2 右击域或者OU的属性中不再出现“组策略”。
用于修复 window2008R2 X64 .NET Framework 3.5.1 ASP.NET Padding Oracle 漏洞(MS10-070)
Window server2008 R2驱动备份
windows server 2008 r2 无线网卡驱动
安装window server 2008 R2 Foundation 系统AD安装
SNMP详细介绍到开发。非常好用的网管接口协议。已在Window2008 R2上使用。
Window2008R2防火墙的开启与web工程的访问配置.pdf
1、离线补丁包,安装时必须要提前安装这个(KB2729094、KB2731771、KB2533623、KB2670838、KB2786081补丁包) 2、WindowsServer2008,R2,64位的IE10浏览器安装包
Windows 7 SP1/Server 2008 R2 SP1 版本实测,其他版本未做实测 自从微软宣布放弃了对 Windows 7 补丁升级的维护后,我们想再享受 Win7 安全升级补丁已不在可能,今天给大家分享适用于 Windows 7 SP1 和 Server 2008...
虚拟机中window server2008r2的安装,计算机改名,关闭防火墙,在文件服务器下安装DFS。
Windows Server 2008 R2系统BUG导致windows缓冲区已满(no buffer space),Windows核心套接字泄露问题导致操作系统套接字资源被耗尽,导致服务器与数据库无法正常对接。
支持本地安装windows server 2008 r2 服务器系统有线网卡驱动
cn_windows_server_2008_standard_enterprise_and_datacenter_with_sp2_x64_dvd_x15-41319.iso
window server 2008 R2下搭建apache+mysql+php 很多人喜欢用wamp环境这个环境请严格按照本人提示的安装包安装因为其他版本的包经本人测试很多搭建都遇到很多问题。
windows2008r2安装.netcore3.1报500.xx错误,各种尝试均无法解决,问题都出在KB2533623-x64上面,而且Windows官网已经下载不到了,双手奉上
thinksystem安装window server2008R2操作手册及驱动程序(包含USB驱动、光纤卡驱动、主板驱动)
用操作系统的ping命令可以查看网络是否良好,但是如果想一直查看,记录日志是最好的选择。自带的不能记录日志,用shell脚本比较麻烦而且没有ping的时间记录,这个小工具或许能解决你的问题,自定义日志文件路径配置...
Windows Server 2008 R2系统BUG导致windows缓冲区已满(no buffer space),Windows核心套接字泄露问题导致操作系统套接字资源被耗尽,导致服务器与数据库无法正常对接。windows 2008 R2解决socket连接不释放补丁包_time...
终于找到Windows Server 2008R2下可运行的Chrome与ChromeDriver的版本,亲测可用,将两个安装打包放一起,方便下载