Microsoft MVP성태의 닷넷 이야기
.NET Framework: 17. Win32_NTLogEvent를 c#에서 wmi 쿼리할 때..에러.. [링크 복사], [링크+제목 복사],
조회: 21914
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

답변이 좀 늦었네요. ^^; 이런 유의 질문은 시간을 갖고 해봐야 하는데...
평일에는 업무가 있다보니 쉽지가 않네요. ^^

보여주신 소스를 저도 한번 실행시켜 봤는데요. 정말 그 부분에서 오류가
발생하네요. ^^
그런데, 자세히 보니까... 오류가 날 수밖에 없는 상황이었습니다.

그 부분을 C#에서는

object obj = mo[ "Message" ];
if ( obj != null )
{
    // 처리...
}

라고 해야 하고, 아마도 VBScript에서 문제가 발생하지 않은 것은... VBScript
의 경우에는 그런 때에 그냥 null을 반환해 주기 때문일 것입니다.

좀 더 구체적으로 들어가보면 해당 메시지를 보니까... 영문 Windows인 경우
다음과 같은 오류 메시지가 있더군요.

Event Type: Information
Event Source: Exception
Event Category: None
Event ID: 0
Date: 2004-10-25
Time: 오후 2:43:30
User: N/A
Description:
The description for Event ID ( 0 ) in Source ( Exception ) cannot be found.
The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. You may be
able to use the /AUXSOURCE= flag to retrieve this description; see Help and
Support for details. The following information is part of the event: Request
format is unrecognized..

즉... 해당 EventID에 대한 설명을 발견할 수 없다는 것인데요. WinNT Event
Log에 출력하기 위해서는 사용하려는 이벤트를 위해 미리 정의된 메시지를
가지는 윈도우즈 리소스를 제작해 두어야 합니다. 그런데, 위의 오류들은 해당
리소스 메시지가 없다는 것인데요. 그로 인해 공통적으로 Event Log가,

The description for Event ID ( 0 ) in Source ( Exception ) cannot be found.
The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. You may be
able to use the /AUXSOURCE= flag to retrieve this description; see Help and
Support for details. The following information is part of the event:

위와 같은 메시지를 출력하고 실제로 도움이 되는 메시지는

Request format is unrecognized

입니다. 그래서, 위의 메시지만을 추출해오면 되기 때문에 결과적으로 mo[
"Message" ]는 다음과 같은 식으로 구해져야 합니다.

string msgText = "";
object objTemp = mo[ "Message" ];
if ( objTemp == null )
{
   object obj = mo[ "InsertionStrings" ];
   string [] msgObj = (string[])obj;
   msgText = msgObj[0]; <--------- 이 부분에서 "Request format is
unrecognized"와 같은 메시지가 구해짐.
} else {
   msgText = (string)objTemp;
}

--
======= (c) .NETXpert ==========
url : http://www.dotnetxpert.com
eml : kevin@dotnetxpert.com
msn: kevin025@magicn.com

MCSD.NET, MVP[VC++]
==============================

"INSIDEAPPLE™" <help@serverinfo.pe.kr.korea> wrote in message
news:OdjypcYtEHA.2624@TK2MSFTNGP11.phx.gbl...
> string rtn = "";
> ManagementObjectSearcher mos = new ManagementObjectSearcher("select *
> from Win32_NTLogEvent WHERE LogFile='Application'");
> ManagementObjectCollection moc = mos.Get();
>
> if(moc.Count > 0)
> {
> foreach(ManagementObject mo in moc)
> {
> rtn += "카테고리 : " + mo["Category"].ToString();
> rtn += "로그파일 : " + mo["Logfile"].ToString();
> rtn += "이벤트코드 : " + mo["EventCode"].ToString();
> rtn += "소스이름 : " + mo["SourceName"].ToString();
> rtn += "타입 : " + mo["Type"].ToString();
> rtn += "이벤트기록시간 : " + mo["TimeWritten"].ToString();
> rtn += mo["Message"].ToString(); -------> 이부분
> //rtn += mo["CategoryString"].ToString(); -------> 이부분
> rtn += mo["ComputerName"].ToString();
> rtn += mo["RecordNumber"].ToString();
> rtn += mo["TimeGenerated"].ToString();
> //rtn += mo["User"].ToString(); -------> 이부분
>
> }
>
> Console.WriteLine(rtn);
>
> 인데요...
>
> 에러부분이 몇개 되는데요.. 등등...
>
> Message 필드가 vbscript로 쿼리할때는 분명히 되는데..
>
> c#에서 쿼리할때에는 없는 System.NullReferenceException 예외를
발생하네요...
>
> 왜 vbscript와 차이가 나는지....
>
> 아시는분 도움좀 부탁드립니다...^^;
>
>
>
>
>
>









[최초 등록일: ]
[최종 수정일: 6/27/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 151  152  153  154  155  156  157  158  159  160  161  162  [163]  164  165  ...
NoWriterDateCnt.TitleFile(s)
969정성태12/31/201040322VC++: 45. Winsock 2 Layered Service Provider - Visual Studio 2010용 프로젝트 [1]파일 다운로드1
968정성태12/30/201026552개발 환경 구성: 94. 개발자가 선택할 수 있는 윈도우에서의 네트워크 프로그래밍 기술 [2]
967정성태12/27/201028344.NET Framework: 197. .NET 코드 - 단일 Process 실행파일 다운로드1
966정성태12/26/201026303.NET Framework: 196. .NET 코드 - 창 흔드는 효과파일 다운로드1
965정성태12/25/201027791개발 환경 구성: 93. MSBuild를 이용한 닷넷 응용프로그램의 다중 어셈블리 출력 빌드파일 다운로드1
964정성태12/21/2010142954개발 환경 구성: 92. 윈도우 서버 환경에서, 최대 생성 가능한 소켓(socket) 연결 수는 얼마일까? [14]
963정성태12/13/201027837개발 환경 구성: 91. MSBuild를 이용한 닷넷 응용프로그램의 플랫폼(x86/x64)별 빌드 [2]파일 다운로드1
962정성태12/10/201022744오류 유형: 110. GAC 등록 - Failure adding assembly to the cache: Invalid file or assembly name.
961정성태12/10/201099747개발 환경 구성: 90. 닷넷에서 접근해보는 PostgreSQL DB [5]
960정성태12/8/201045046.NET Framework: 195. .NET에서 코어(Core) 관련 CPU 정보 알아내는 방법파일 다운로드1
959정성태12/8/201031862.NET Framework: 194. Facebook 연동 - API Error Description: Invalid OAuth 2.0 Access Token
958정성태12/7/201028844개발 환경 구성: 89. 배치(batch) 파일에서 또 다른 배치 파일을 동기 방식으로 실행 및 반환값 얻기 [2]
957정성태12/6/201031578디버깅 기술: 31. Windbg - Visual Studio 디버그 상태에서 종료해 버리는 응용 프로그램 [3]
953정성태11/28/201036825.NET Framework: 193. 페이스북(Facebook) 계정으로 로그인하는 C# 웹 사이트 제작 [5]
952정성태11/25/201025253.NET Framework: 192. GC의 부하는 상대적인 것! [4]
950정성태11/18/201076629.NET Framework: 191. ClickOnce - 관리자 권한 상승하는 방법 [17]파일 다운로드2
954정성태11/29/201048626    답변글 .NET Framework: 191.1. [답변] 클릭원스 - 요청한 작업을 수행하려면 권한 상승이 필요합니다. (Exception from HRESULT: 0x800702E4) [2]
949정성태11/16/201027163오류 유형: 109. System.ServiceModel.Security.SecurityNegotiationException
948정성태11/16/201035949.NET Framework: 190. 트위터 계정으로 로그인하는 C# 웹 사이트 제작 [7]파일 다운로드1
947정성태11/14/201041645.NET Framework: 189. Mono Cecil로 만들어 보는 .NET Decompiler [1]파일 다운로드1
946정성태11/11/201041463.NET Framework: 188. .NET 64비트 응용 프로그램에서 왜 (2GB) OutOfMemoryException 예외가 발생할까? [1]파일 다운로드1
945정성태11/11/201024989VC++: 44. C++/CLI 컴파일 오류 - error C4368: mixed types are not supported
944정성태11/11/201031459VC++: 43. C++/CLI 컴파일 오류 - error C2872: 'IServiceProvider' : ambiguous symbol could be ...
943정성태11/8/201030577디버깅 기술: 30. windbg ".loadby sos" 명령어 [2]
942정성태11/7/201042171.NET Framework: 187. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 [7]파일 다운로드3
941정성태11/6/201025082.NET Framework: 186. windbg로 확인하는 .NET CLR LCG 메서드(DynamicMethod) [1]파일 다운로드1
... 151  152  153  154  155  156  157  158  159  160  161  162  [163]  164  165  ...