控制台应用程序仅适用于vs2010

时间:2012-03-28 11:34:02

标签: c# log4net

我写了一个控制台应用程序项目。

当我通过visual studio 2010进行调试时,它会根据需要运行并执行。

当我从cmd运行它的exe时,

我没有看到(重定向到控制台)的log4net

控制台上没有显示错误

数据库未更新。

这会导致什么?

32位进程与64?

我的构建是32位。

我使用VS2010 dotNet 4在win7上运行

更新:

我的exe工作。

但我无法通过视觉工作室附加到它

Log4net不会向控制台显示日志

这是我的配置文件btw

<?xml version="1.0"?>
<configuration>
   <configSections>
    <section name="DBSubscriptionStorageConfig"
         type="NServiceBus.Config.DBSubscriptionStorageConfig, NServiceBus.Core" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>

  <connectionStrings>
    <add name="ToolbarsDB" connectionString="server=DEV-DBSRV50;database=TOOLBARSDB;PASSWORD=toolbarsapp;UID=toolbarsapp" providerName="System.Data.SqlClient" />
  </connectionStrings>


  <log4net>
    <root>
      <level value="DEBUG" />
          <appender-ref ref="LogFileAppender" />
          <appender-ref ref="ConsoleAppender" />
      <level value="INFO" />
          <appender-ref ref="LogFileAppender" />
          <appender-ref ref="ConsoleAppender" />
      <level value="ERROR" />
          <appender-ref ref="LogFileAppender" />
          <appender-ref ref="ConsoleAppender" />
      <level value="FATAL" />
          <appender-ref ref="LogFileAppender" />
          <appender-ref ref="ConsoleAppender" />
    </root>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
      <param name="File" value="log.txt" />
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout" xmlns="">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>
  </log4net>

  <!--Publisher-->
  <DBSubscriptionStorageConfig>
    <NHibernateProperties>
      <add Key="connection.provider"
           Value="NHibernate.Connection.DriverConnectionProvider"/>
      <add Key="connection.driver_class"
           Value="NHibernate.Driver.SqlClientDriver"/>
      <add Key="connection.connection_string"
           Value="Data Source=DEV-DBSRV80;Initial Catalog=CPServicesDB;Persist Security Info=True;User ID=CPServicesDBUser;Password=oire^3jd!"/>
      <add Key="dialect"
           Value="NHibernate.Dialect.MsSql2005Dialect"/>
    </NHibernateProperties>
  </DBSubscriptionStorageConfig>
  <!-- End Publisher-->

  <appSettings>
    <add key="assemblyName" value="Conduit.CPServices.Logic.Bundlator"/>
    <add key="typeName" value="Conduit.CPServices.Logic.Bundlator.BundlatorMessageHandlers"/>
  </appSettings>

  <runtime>
    <loadFromRemoteSources enabled="true"/>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NHibernate" publicKeyToken="AA95F207798DFDB4" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-3.2.0.4000" newVersion="3.2.0.4000"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CPServicesGeneralServiceBehavior">
          <serviceMetadata httpGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您在Command Prompt中运行应用程序时看不到输出,但它在Debug Mode中正常工作。

您是否有机会从app.config阅读设置?也许您需要复制Application XML Configuration File以及Executable

该文件通常称为MyApplication.exe.config