我正在尝试学习如何从 java eclipse 登录到事件查看器,并且我已经阅读了有关堆栈溢出的 api、各种站点和类似问题。
但是,当我按照这些步骤进行操作时,我总是会得到:
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");
}
}