Domanda

Having problem to write on windows event log with c#.

public static void writeToEventLog(string msgGrid, string msgIntern, EventLogEntryType entryType)  
{  
    string grp = "Application"; // Fixed because cant create new but happy if bellow works.  
    if (!EventLog.SourceExists(msgGrid)) { EventLog.CreateEventSource(msgGrid, grp); }  
    EventLog.WriteEntry(msgGrid, msgIntern, entryType);  
}  

// The folowing code dont put entry on event log:

string msgGrid = "pdtidtijejrnexhr";  
string msgIntern = "*-* [Dt:2013-10-31 11:41:10.00][digkufdufe:{[<2013-10-31 11:41:09> {jpdriskrt01} jpdriskrt01[172.22.3.70:57010]> [pdtidhry jrnecidr]]} : {}] >>#[eydshr:(rhrdhruiweirts.hrt.krt.krtjelr.jt.jpdrtjelkrhtw.<dnjr>b__1)]>>#[jpdrtjelkrhtw]\\[pdtidtijejrnexhr]\r\n";

writeToEventLog(msgGrid, msgIntern, EventLogEntryType.FailureAudit);

// The folowing code works OK:

writeToEventLog("t1", "t2", EventLogEntryType.FailureAudit);

There is some constraint about log content or size ?

È stato utile?

Soluzione

It looks like your source ("pdtidtijejrnexhr") doesn't exist yet, but "t1" does, so that's why the other snippet of code is working. Also, you may have to double-up your braces ({ and }), but I'm not positive on that one. ({{ and }}, respectively).

I don't think "t1" comes with Windows by default.. I suspect that your code successfully created it at one point (maybe in combination with when you weren't using braces in a log message?)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top