3
我想學習如何從java eclipse登錄到事件查看器,並且我已經閱讀了堆棧溢出中的api,各種網站和類似問題。NTEventLogAppender的源代碼示例?
但是,當我按照步驟我總是得到:
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.log4j.nt.NTEventLogAppender.registerEventSource(Ljava/lang/String;Ljava/lang/String;)I
at org.apache.log4j.nt.NTEventLogAppender.registerEventSource(Native Method)
at org.apache.log4j.nt.NTEventLogAppender.<init>(NTEventLogAppender.java:79)
at org.apache.log4j.nt.NTEventLogAppender.<init>(NTEventLogAppender.java:65)
什麼是源應該是什麼?
如果任何人都可以展示這樣一個非常好的程序的完整示例。請儘可能詳細地介紹,謝謝。
我的代碼現在的問題是:
package Output;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.nt.NTEventLogAppender;
public class EventLog {
public static void main(String[] args)
{
Logger myLogger = Logger.getLogger(EventLog.class);
String mySource = "the source";
PatternLayout myLayout = new PatternLayout("[%c][%l][%p][%thread]: %m%n");
NTEventLogAppender eventLogAppender= new NTEventLogAppender(mySource,myLayout);
ConsoleAppender consoleAppender= new ConsoleAppender(myLayout);
myLogger.addAppender(consoleAppender);
myLogger.addAppender(eventLogAppender);
myLogger.setLevel(Level.WARN);
myLogger.fatal("Come on print");
}
}