代码如下
EventLog log = gcnew EventLog();
try
{
log.Source = "我的应用程序";
log.WriteEntry("处理信息1", EventLogEntryType::Information);
log.WriteEntry("处理信息2", EventLogEntryType::Information);
throw gcnew System::IO::FileNotFoundException("readme.txt文件未找到");
}
catch (System::IO::FileNotFoundException ^exception)
{
log.WriteEntry("处理信息2", EventLogEntryType::Error);
}
我这样写了后会报错:无法将参数 1 从“System::Diagnostics::EventLog ^”转换为“System::String ^”
就是那个EventLog log = gcnew EventLog();这里
using namespace System;
using namespace System::Collections;
#using "D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\System.dll"
using namespace System::Diagnostics;
COfficeHandle::COfficeHandle()
{
System::Diagnostics::EventLog^ log = gcnew System::Diagnostics::EventLog();
try
{
log->Source = "我的应用程序";
log->WriteEntry( "处理信息1", System::Diagnostics::EventLogEntryType::Information );
log->WriteEntry( "处理信息2", EventLogEntryType::Information );
throw gcnew System::IO::FileNotFoundException( "readme.txt文件未找到" );
}
catch ( System::IO::FileNotFoundException ^exception )
{
log->WriteEntry( "处理信息2", EventLogEntryType::Error );
}
}
照 这个试试 我编译通过了的 他那个是c#里面调用的方法 你应该跟我一样是在c++的控制台调用吧
System.Diagnostics.EventLog appLog = new System.Diagnostics.EventLog();