Windows服务 - 事件日志 [英] Windows Service - Event Log
问题描述
我正在构建一个将部署在Windows上的Windows服务
server 2003我希望将活动写入事件日志,我想要b $ b想要它自己的日志叫(''CustomLog'')
以下是我到目前为止...它的构建很好但是当我开始时
服务我收到以下错误。
---------------------------
服务
---------------------------
CWindowService本地计算机上的服务启动然后停止。
如果没有工作要做,有些服务会自动停止,例如,性能日志和警报服务。
>
---------------------------
OK
- --------------------------
我做错了什么?在这段代码之后我就有了这一行....而且
从来没有问题。
EventLog.WriteEntry(刷新成功启动。);
// 1。创建源,如果它尚不存在。
if(!EventLog.SourceExists(" CustomLog"))
{
EventLog .CreateEventSource(" CustomLog"," MyNewLog");
}
// 2。创建一个EventLog实例并分配其源。
EventLog myLog = new EventLog();
myLog.Source =" CustomLog";
// 3。在事件日志中写入一个信息性条目。
myLog.WriteEntry(写入事件日志。);
I am building an windows service that is to be deployed on a windows
server 2003 and I want to have activity written to the event log, I
want its own log called (''CustomLog'')
Below is what I have so far...its builds fine but when I go to start
the service i get the following error.
---------------------------
Services
---------------------------
The CWindowService service on Local Computer started and then stopped.
Some services stop automatically if they have no work to do, for
example, the Performance Logs and Alerts service.
---------------------------
OK
---------------------------
What am I doing wrong? Right after this code I have this line....and it
never had an issue.
EventLog.WriteEntry("Refresh started successfully.");
//1. Create the source, if it does not already exist.
if (!EventLog.SourceExists("CustomLog"))
{
EventLog.CreateEventSource("CustomLog", "MyNewLog");
}
//2. Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "CustomLog";
//3. Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.");
推荐答案
没有看到更多的开始代码,我无法肯定地说,
然而,当我最近使用这个时,我发现有了
在我的OnStart事件中评估代码我倾向于收到
相同的错误。我建议你做的是添加一个组件计时器给服务(不是表格计时器)
并将你的代码放在计时器的累计事件中。然后在你的OnStart方法中你只需激活计时器。
-Bill
Without seeing more of the start code i couldn''t say for sure,
however, when I was working with this recently I found that by having
evaluating code in my OnStart event I had a tendancy of recieving the
same error. What I would recommend you do is add a component timer to
the service(not a form timer) and put your code in the Elapsed event of
the timer. Then in your OnStart method you just activate the timer.
-Bill
你好,
您需要发布更多代码或更多详细信息。
你在哪里运行这个?
你的onStart是什么看起来像是什么?
您是否在onStart中创建了一个新线程?
通常我在onStart中创建并启动一个线程是
做真实的人。通过这种方式,onStart立即返回
。
-
-
Ignacio Machin,>
ignacio.machin AT dot.state.fl.us
佛罗里达州交通局
< pi ***** @ hotmail .COM>在留言中写道
news:11 ********************** @ u72g2000cwu.googlegr oups.com ...
Hi,
You need to post more code, or more details at least.
Where are you running this?
What your onStart looks like?
Are you creating a new thread in the onStart ?
Usually what I do is in the onStart just create and Start a thread that is
the one who does the real thing. in this way the onStart returns
inmediately.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<pi*****@hotmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
我正在构建一个将部署在Windows服务器2003上的Windows服务,我希望将活动写入事件日志,我想要自己的日志调用('''CustomLog '')
以下是我到目前为止...它构建正常但是当我开始服务时我得到以下错误。
---------------------------
服务
-------------- -------------
本地计算机上的CWindowService服务启动然后停止。
如果没有工作要做,有些服务会自动停止。
示例,性能日志和警报服务。
---------------------------
OK
- -------------------------
我做错了什么?在这段代码之后,我有了这一行....而且它从未出现过问题。
EventLog.WriteEntry(刷新成功启动。);
/ / 1。创建源,如果它尚不存在。
if(!EventLog.SourceExists(" CustomLog")))
EventLog.CreateEventSource(" CustomLog"," MyNewLog") );
}
// 2。创建一个EventLog实例并分配其源。
EventLog myLog = new EventLog();
myLog.Source =" CustomLog";
// 3。在事件日志中写入一个信息性条目。
myLog.WriteEntry(写入事件日志。);
I am building an windows service that is to be deployed on a windows
server 2003 and I want to have activity written to the event log, I
want its own log called (''CustomLog'')
Below is what I have so far...its builds fine but when I go to start
the service i get the following error.
---------------------------
Services
---------------------------
The CWindowService service on Local Computer started and then stopped.
Some services stop automatically if they have no work to do, for
example, the Performance Logs and Alerts service.
---------------------------
OK
---------------------------
What am I doing wrong? Right after this code I have this line....and it
never had an issue.
EventLog.WriteEntry("Refresh started successfully.");
//1. Create the source, if it does not already exist.
if (!EventLog.SourceExists("CustomLog"))
{
EventLog.CreateEventSource("CustomLog", "MyNewLog");
}
//2. Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "CustomLog";
//3. Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.");
凭据是什么服务在哪?有可能
服务'的帐户没有必要的权限写入
事件日志。
-
HTH,
Kevin Spencer
Microsoft MVP
专业鸡肉沙拉炼金术士
大厚片由很多小薄片组成。
< pi ***** @ hotmail.com>在留言中写道
news:11 ********************** @ u72g2000cwu.googlegr oups.com ...
What credentials is the Service running under? It is possible that the
Service''s account does not have the necessary permission to write to the
Event Log.
--
HTH,
Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist
Big thicks are made up of lots of little thins.
<pi*****@hotmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
我正在构建一个将部署在Windows服务器2003上的Windows服务,我希望将活动写入事件日志,我想要自己的日志调用('''CustomLog '')
以下是我到目前为止...它构建正常但是当我开始服务时我得到以下错误。
---------------------------
服务
-------------- -------------
本地计算机上的CWindowService服务启动然后停止。
如果没有工作要做,有些服务会自动停止。
示例,性能日志和警报服务。
---------------------------
OK
- -------------------------
我做错了什么?在这段代码之后,我有了这一行....而且它从未出现过问题。
EventLog.WriteEntry(刷新成功启动。);
/ / 1。创建源,如果它尚不存在。
if(!EventLog.SourceExists(" CustomLog")))
EventLog.CreateEventSource(" CustomLog"," MyNewLog") );
}
// 2。创建一个EventLog实例并分配其源。
EventLog myLog = new EventLog();
myLog.Source =" CustomLog";
// 3。在事件日志中写入一个信息性条目。
myLog.WriteEntry(写入事件日志。);
I am building an windows service that is to be deployed on a windows
server 2003 and I want to have activity written to the event log, I
want its own log called (''CustomLog'')
Below is what I have so far...its builds fine but when I go to start
the service i get the following error.
---------------------------
Services
---------------------------
The CWindowService service on Local Computer started and then stopped.
Some services stop automatically if they have no work to do, for
example, the Performance Logs and Alerts service.
---------------------------
OK
---------------------------
What am I doing wrong? Right after this code I have this line....and it
never had an issue.
EventLog.WriteEntry("Refresh started successfully.");
//1. Create the source, if it does not already exist.
if (!EventLog.SourceExists("CustomLog"))
{
EventLog.CreateEventSource("CustomLog", "MyNewLog");
}
//2. Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "CustomLog";
//3. Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.");
这篇关于Windows服务 - 事件日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!