"無法存取 IIS Metabase。您沒有足夠權限存取您電腦上的 IIS 網站。"
上網找解決方法時,發現大部份人都說是新安裝.net Framework2.0再裝IIS才導致的錯誤,只要重新註冊即可,指令如下:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis.exe -i最後...用了一個鳥方式...給大家參考
如有正解...再請多多指教囉XD
CREATE TABLE [dbo].[Log] (
[Id] [int] IDENTITY (1, 1) NOT NULL,
[Date] [datetime] NOT NULL,
[Thread] [varchar] (255) NOT NULL,
[Level] [varchar] (50) NOT NULL,
[Logger] [varchar] (255) NOT NULL,
[Message] [varchar] (4000) NOT NULL,
[Exception] [varchar] (2000) NULL
)
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=[資料庫連線];initial catalog=[資料庫名稱];integrated security=false;persist security info=True;User ID=[使用者];Password=[密碼]" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@exception" />
<dbType value="String" />
<size value="2000" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>
</appender>
<root>
<level value="All" />
←分為七級,可自行設定OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL
←這邊設定所有等級的log都要寫入資料庫做記錄
<appender-ref ref="AdoNetAppender" />
</root>
步驟四:Test.aspx
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(WebForm1));
protected void Page_Load(object sender, EventArgs e){log.Info("^_^");
}
步驟五:看資料庫有沒有成功寫入資料