我的app.config文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="OutlookAddIn4.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>
<OutlookAddIn4.Properties.Settings>
<setting name="user" serializeAs="String">
<value/>
</setting>
<setting name="token" serializeAs="String">
<value/>
</setting>
<setting name="serverurl" serializeAs="String">
<value>https://www.MyApp.com</value>
</setting>
<setting name="Setting" serializeAs="String">
<value/>
</setting>
</OutlookAddIn4.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup>
</configuration>
我的AssemblyInfo.cs显示:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config")]
是的,我有一个log4net.config文件,内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
</configSections>
<log4net>
<root>
<level value="ALL"/>
<appender-ref ref="RollingFileAppender"/>
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="${APPDATA}\AgreeDo\AgreeDoPluginForOutlook-log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="5MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
在我的主类中(Outlook插件:ThisAddIn.cs) 我使用:
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
在启动方法中,我使用:
log4net.Config.XmlConfigurator.Configure();
执行此行后,我将在控制台中获得以下输出。
log4net:ERROR Failed to find configuration section 'log4net' in the application's .config file. ...
现在,我想知道为什么我会在控制台上收到此错误消息。 更重要的是:日志文件写在我的开发机器上!但是当我将外接程序部署到另一台计算机时,并不会创建/写入该文件。
有什么主意吗?
最佳国王 汉尼斯