<?xml version="1.0" encoding="utf-8"?>
<!--
  Web API 应用配置文件
  部署到 IIS 时，需要将此文件复制到站点根目录
-->
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

  <log4net>
    <appender name="ErrorFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="App_Data\logs\error.log" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <threshold value="ERROR" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline%exception%newline" />
      </layout>
    </appender>
    <appender name="AllFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="App_Data\logs\webapi.log" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline%exception%newline" />
      </layout>
    </appender>
    <root>
      <level value="INFO" />
      <appender-ref ref="AllFileAppender" />
      <appender-ref ref="ErrorFileAppender" />
    </root>
  </log4net>
  <connectionStrings>
    <!-- 业务库连接串 -->
    <add name="BusinessConnection"
         connectionString="Server=localhost;Database=cnc_business;Uid=root;Pwd=root;Charset=utf8mb4;SslMode=None;" />
    <!-- 日志库连接串 -->
    <add name="LogConnection"
         connectionString="Server=localhost;Database=cnc_log;Uid=root;Pwd=root;Charset=utf8mb4;SslMode=None;" />
  </connectionStrings>

  <appSettings>
    <!-- 禁用 OWIN 自动发现（本项目使用 Global.asax + WebApiConfig） -->
    <add key="owin:AutomaticAppStartup" value="false" />
    <!-- JWT认证密钥，生产环境请更换 -->
    <add key="JwtSecret" value="CncDataSystem_2026_SecretKey_For_Jwt_Token_Generation_Min32Chars" />
    <!-- Token过期时间（小时） -->
    <add key="TokenExpirationHours" value="24" />
    <!-- 模拟器网关地址（默认 http://localhost:9000） -->
    <add key="SimulatorGatewayUrl" value="http://localhost:9000" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
    <!-- 临时开启详细错误用于联调 -->
    <customErrors mode="Off" />
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
      </dependentAssembly>
      <!-- MySqlConnector 依赖的程序集绑定重定向 -->
      <dependentAssembly>
        <assemblyIdentity name="System.Memory" culture="neutral" publicKeyToken="cc7b13ffcd2ddd51" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" culture="neutral" publicKeyToken="cc7b13ffcd2ddd51" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks.Extensions" culture="neutral" publicKeyToken="cc7b13ffcd2ddd51" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
