Microsoft MVP성태의 닷넷 이야기
.NET Framework: 17. Win32_NTLogEvent를 c#에서 wmi 쿼리할 때..에러.. [링크 복사], [링크+제목 복사],
조회: 21856
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13768정성태10/15/20245397C/C++: 179. C++ - _O_WTEXT, _O_U16TEXT, _O_U8TEXT의 Unicode stream 모드파일 다운로드2
13767정성태10/14/20244773오류 유형: 929. bpftrace 수행 시 "ERROR: Could not resolve symbol: /proc/self/exe:BEGIN_trigger"
13766정성태10/14/20244555C/C++: 178. C++ - 파일에 대한 Text 모드의 "translated" 동작파일 다운로드1
13765정성태10/12/20245267오류 유형: 928. go build 시 "package maps is not in GOROOT" 오류
13764정성태10/11/20245632Linux: 85. Ubuntu - 원하는 golang 버전 설치
13763정성태10/11/20244988Linux: 84. WSL / Ubuntu 20.04 - bpftool 설치
13762정성태10/11/20245010Linux: 83. WSL / Ubuntu 22.04 - bpftool 설치
13761정성태10/11/20244917오류 유형: 927. WSL / Ubuntu - /usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
13760정성태10/11/20245450Linux: 82. Ubuntu - clang 최신(stable) 버전 설치
13759정성태10/10/20246367C/C++: 177. C++ - 자유 함수(free function) 및 주소 지정 가능한 함수(addressable function) [6]
13758정성태10/8/20245579오류 유형: 926. dotnet tools를 sudo로 실행하는 경우 command not found
13757정성태10/8/20245522닷넷: 2306. Linux - dotnet tool의 설치 디렉터리가 PATH 환경변수에 자동 등록이 되는 이유
13756정성태10/8/20245630오류 유형: 925. ssh로 docker 접근을 할 때 "... malformed HTTP status code ..." 오류 발생
13755정성태10/7/20246029닷넷: 2305. C# 13 - (9) 메서드 바인딩의 우선순위를 지정하는 OverloadResolutionPriority 특성 도입 (Overload resolution priority)파일 다운로드1
13754정성태10/4/20245579닷넷: 2304. C# 13 - (8) 부분 메서드 정의를 속성 및 인덱서에도 확대파일 다운로드1
13753정성태10/4/20245596Linux: 81. Linux - PATH 환경변수의 적용 규칙
13752정성태10/2/20246282닷넷: 2303. C# 13 - (7) ref struct의 interface 상속 및 제네릭 제약으로 사용 가능 [6]파일 다운로드1
13751정성태10/2/20245408C/C++: 176. C/C++ - ARM64로 포팅할 때 유의할 점
13750정성태10/1/20245293C/C++: 175. C++ - WinMain/wWinMain 호출 전의 CRT 초기화 단계
13749정성태9/30/20245537닷넷: 2302. C# - ssh-keygen으로 생성한 Private Key와 Public Key 연동파일 다운로드1
13748정성태9/29/20245743닷넷: 2301. C# - BigInteger 타입이 byte 배열로 직렬화하는 방식
13747정성태9/28/20245597닷넷: 2300. C# - OpenSSH의 공개키 파일에 대한 "BEGIN OPENSSH PUBLIC KEY" / "END OPENSSH PUBLIC KEY" PEM 포맷파일 다운로드1
13746정성태9/28/20245691오류 유형: 924. Python - LocalProtocolError("Illegal header value ...")
13745정성태9/28/20245552Linux: 80. 리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (lldb)
13744정성태9/27/20245983닷넷: 2299. C# - Windows Hello 사용자 인증 다이얼로그 표시하기파일 다운로드1
13743정성태9/26/20246430닷넷: 2298. C# - Console 프로젝트에서의 await 대상으로 Main 스레드 활용하는 방법 [1]
1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...