简体   繁体   English

log4net compact framework 3.5没有app.config来添加文件追加器

[英]log4net compact framework 3.5 No app.config to add file appenders

I am developing a log4net using CF 3.5 VS 2008 on windows mobile 6. 我正在使用Windows Mobile 6上的CF 3.5 VS 2008开发一个log4net。

I have used log4net before in my windows xp applications, and I always put the configuration in the app.config file. 我之前在windows xp应用程序中使用过log4net,我总是将配置放在app.config文件中。

However, this is my first time using log4net with CF3.5. 但是,这是我第一次使用带有CF3.5的log4net。 And I have noticed there is no app.config file, and when I try to add a new item there is no template for one. 我注意到没有app.config文件,当我尝试添加新项目时,没有模板。 Am I missing something here? 我在这里错过了什么吗?

If 3.5 doesn't have a app.config file. 如果3.5没有app.config文件。 Where can I put my log4net configuration? 我在哪里可以放置我的log4net配置? I would like to log4net using the file appender and save the log in the directory where the application is executing from. 我想使用文件appender log4net并将日志保存在执行应用程序的目录中。

Many thanks for any suggestions, 非常感谢任何建议,

Compact framework does not support app.config files but you can emulate such behavior. Compact框架不支持app.config文件,但您可以模拟此类行为。

Create a xml with setting and then read content of that file. 使用设置创建xml,然后读取该文件的内容。

I found this workaround that work for me: 我发现这个解决方法对我有用:

http://www.eggheadcafe.com/articles/dotnetcompactframework_app_config.asp http://www.eggheadcafe.com/articles/dotnetcompactframework_app_config.asp

This reaction is a bit late, and probably you have solved it already. 这个反应有点晚了,可能你已经解决了。 However there might be some other users that have the same problem. 但是,可能有其他一些用户遇到同样的问题。

You can also specify that you want to use a different config-file using the XmlConfiguratorAttribute. 您还可以使用XmlConfiguratorAttribute指定要使用其他配置文件。 See here . 看到这里 For instance you could specify the log4net-configuration in 'log4net.config' which is in your bin-directory and add in the assemblyInfo.cs: 例如,您可以在bin目录中的'log4net.config'中指定log4net-configuration并添加到assemblyInfo.cs中:

[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.config",Watch=true)]

Ruben, This won't work because XmlConfiguratorAttribute is not available from log4net to compact framework. Ruben,这不起作用,因为从log4net到紧凑框架不能使用XmlConfiguratorAttribute

Instead, you can use XmlConfigurator.Configure("filename.config") replacing filename.config by the path to your log4net configuration file. 相反,您可以使用XmlConfigurator.Configure("filename.config")filename.config替换为log4net配置文件的路径。

I've put this on the main program class of a Windows Application on my mobile application. 我把它放在我的移动应用程序上的Windows应用程序的主程序类中。

Hugs :) 拥抱:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM