使用NLog的代码 :
Logger logger = LogManager.GetCurrentClassLogger();
LogEventInfo lei = new LogEventInfo();
lei.Properties["Operator_name"] = Opeator_Name;
lei.Properties["Operator_Type"] = Operator_Type;
lei.Properties["DateTime"] = DateTime.Now;
lei.Properties["IP"] = GetClientIPOrAdd.GetIP();
lei.Properties["Operation"] = Operation;
lei.Level = LogLevel.Info;
logger.Log(lei);
编译没问题,在运行的时候, 'Logger logger = LogManager.GetCurrentClassLogger();'出现错误提示:
NLog.NLogConfigurationException: Target logfile not found.
我的NLog.config文件:
<target xsi:type="Database" name="LogOnlog" connectionStringName ="DataBase" > <commandText> Insert into MyLog(Operator_name,Operator_Type,IP,DateTime,Operation) Values(@Operator_name,@Operator_Type,@IP,@DateTime,@Operation); </commandText> <parameter name = "@Operator_name" layout = "${event-context;item=Operator_name}"/> <parameter name = "@Operator_Type" layout = "${event-context;item=Operator_Type}" /> <parameter name = "@DateTime" layout = "${event-context;item=DateTime}"/> <parameter name = "@IP" layout = "${event-context;item=IP}" /> <parameter name = "@Operation" layout = "${event-context;item=Operation}" /> </target> </targets> <rules> <logger name="*" minlevel="Trace " writeTo="LogOnlog"/> </rules>
http://www.cnblogs.com/tider1999/p/4308440.html