
下载log net (Google log net) unzip log net 运行VS 新建 c# Windows应用程序 添加引用Log NET 新建一个应用程序配置文件nfig(具体内容附在后面) 打开Form cs 在Namespace上添加一行 [assembly: log net Config DOMConfigurator(Watch=true)] (或者 编辑Assembly cs文件 添加如下内容: [assembly:log net Config DOMConfigurator( ConfigFileExtension= config Watch=true)] ) 在类Form 中添加一个静态变量 private static readonly log net ILog log = log net LogManager GetLogger(System Reflection MethodBase GetCurrentMethod() DeclaringType); 添加一个按钮 在按钮处理函数中添加一行 log Warn( 你好! ); 运行程序 点一下按钮 OK 打开Bin\Debug\log file txt 可以看到 你好 附nfig <xml version= encoding= utf > <configuration> <! Register a section handler for the log net section > <configSections> <section name= log net type= System Configuration IgnoreSectionHandler /> </configSections> <appSettings> <! To enable internal log net logging specify the following appSettings key > <! <add key= log net Internal Debug value= true /> > </appSettings> <! This section contains the log net configuration settings > <log net> <! Define some output appenders > <appender name= LogFileAppender type= log net Appender FileAppender > <param name= File value= log file txt /> <! Example using environment variables in params > <! <param name= File value= ${TMP}\\log file txt /> > <param name= AppendToFile value= true /> <! An alternate output encoding can be specified > <! <param name= Encoding value= unicodeFFFE /> > <layout type= log net Layout PatternLayout > <param name= Header value= [Header]\r\n /> <param name= Footer value= [Footer]\r\n /> <param name= ConversionPattern value= %d [%t] % p %c [%x] <%X{auth}> %m%n /> </layout> <! Alternate layout using XML <layout type= log net Layout XMLLayout /> > </appender> <! Setup the root category add the appenders and set the default level >
<root> <level value= ALL /> <appender ref ref= LogFileAppender /> <! <appender ref ref= A /> > </root> <! Specify the level for some specific categories > <logger name= SLog net Form > <! <appender ref ref= B /> > <level value= ALL /> <appender ref ref= RollingLogFileAppender /> </logger> </log net> </configuration> nfig <xml version= encoding= utf > <configuration> <! Register a section handler for the log net section > <configSections> <section name= log net type= System Configuration IgnoreSectionHandler /> </configSections> <appSettings> <! To enable internal log net logging specify the following appSettings key > <! <add key= log net Internal Debug value= true /> > </appSettings> <! This section contains the log net configuration settings > <log net> <! Define some output appenders > <appender name= LogFileAppender type= log net Appender FileAppender > <param name= File value= log file txt /> <! Example using environment variables in params > <! <param name= File value= ${TMP}\\log file txt /> > <param name= AppendToFile value= true /> <! An alternate output encoding can be specified > <! <param name= Encoding value= unicodeFFFE /> > <layout type= log net Layout PatternLayout > <param name= Header value= [Header]\r\n /> <param name= Footer value= [Footer]\r\n /> <param name= ConversionPattern value= %d [%t] % p %c [%x] <%X{auth}> %m%n /> </layout> <! Alternate layout using XML <layout type= log net Layout XMLLayout /> > </appender> <! Setup the root category add the appenders and set the default level > <root> <level value= ALL /> <appender ref ref= LogFileAppender /> <! <appender ref ref= A /> > </root> <! Specify the level for some specific categories > <logger name= SLog net Form > <! <appender ref ref= B /> > <level value= ALL /> <appender ref ref= RollingLogFileAppender /> </logger> </log net> </configuration> //调用 using System; using System Collections Generic; using System ComponentModel; using System Data; using System Drawing; using System Text; using System Windows Forms; using log net; [assembly: log net Config DOMConfigurator(Watch = true)] namespace WindowsApplication { public partial class Form : Form { public Form () { InitializeComponent(); } private static readonly log net ILog log = log net LogManager GetLogger(System Reflection MethodBase GetCurrentMethod() DeclaringType); private void button _Click(object sender EventArgs e) { log Warn( 你好! ); } } lishixinzhi/Article/program/net/201311/11537
我以前做过接条码扫描仪的程序,刚好条码扫描仪是有说明书的,有一个设置是扫描完成后带一个enter键的输入,具体你的二维码扫描起是什么样的工作模式我就不清楚了。简单的来说,这一类的设备都是都是数据输入设备,winform的控件都会有类似的事件。在事件触发后写你的代码就可以了
以上就是关于在C#中使用LOG4NET(winform程序)全部的内容,包括:在C#中使用LOG4NET(winform程序)、c#winform程序,一直接收二维码扫描,扫到二维码信息进行 *** 作,求大神给个小例子,一直没鼓捣出来、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)