1

我写了一个小bat文件:

@echo off

rem runs the {arg[0].exe} - using its fully qualified name
%~f1

IF %errorlevel% NEQ 0 
(set boolResult=False) 
ELSE 
(set boolResult=True) 


rem case1 
EVENTCREATE /T ERROR /ID 700 /L "MyTest Application" /D "exitcode: %errorlevel%; session id is %SessionName%"

rem case3
EVENTCREATE /T ERROR /ID 700 /L APPLICATION /D "exitcode: %boolResult%; session id is %SessionName%"

rem case4 
EVENTCREATE /T ERROR /ID 700 /L APPLICATION /D "exitcode: %errorlevel%; session id is %SessionName%"

我有一些问题,如果你能帮助我...

  1. 案例1:我收到以下错误:

    错误:“MyTest 应用程序”日志不存在。无法创建活动。

*通过高级(c#)代码初始事件日志的唯一方法?

  1. case3:如何将字符串与一些 bat 变量连接起来?

  2. case4:如何在描述中添加换行符?

“退出代码:%boolResult%\n 会话 ID 是 %SessionName%”

没有那样做。

感谢您的帮助

4

1 回答 1

0

The only way to initial eventlog in through high-leve (c#) code?

This is correct, there is no command line tool to create new event logs. One option here would be to use a PowerShell script and use the System.Diagnostics.Eventlog class.


case3: How can I concatenate a string with some bat variable ?

The way you do is right, so your log entry text

EVENTCREATE /T ERROR /ID 700 /L "MyTest Application" /D "exitcode: %errorlevel%; session id is %SessionName%"

should expand to:

EVENTCREATE /T ERROR /ID 700 /L "MyTest Application" /D "exitcode: 0; session id is Console"

case4: How do I add a newline in the description?

You can't. There is no way of providing a newline via command line parameters.

于 2010-05-27T09:58:26.147 回答