English 中文(简体)
日 本 AdoNetAppender在网络应用中不伐木成 s
原标题:log4net AdoNetAppender not logging into sql azure db in web application

我一直在试图将任何信息或错误输入我的A.K.A.K.A.的网络应用中,没有成功,也没有任何可解释的错误。 我正试图利用ADONetAppender的以下网站:

<configuration>
  <configSections>
    <section name="log4net"
         type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
         />
  </configSections>
  <log4net>
    <appSettings>
      <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="1" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data,
 Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="Server=;Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True" />
      <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="DEBUG" />
      <appender-ref ref="ADONetAppender" />
    </root>
  </log4net>

....

在我的全球应用中 第一部分

 void Application_Start(object sender, EventArgs e)
            {
                // Code that runs on application startup
                log4net.Config.XmlConfigurator.Configure();


            }

然后试图记录:

 readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

 protected void Button1_Click(object sender, EventArgs e)
    {
        if (_logger.IsInfoEnabled)
            _logger.Info("Performance sensitive Info message");
        _logger.Info("testing web role into Poqlogging");
        _logger.Error("new error",new Exception("new exception"));
    }

所有这一切都与我能够说得不上。

最佳回答

根据你提供的上述信息,一些事情可能是错误的。 更好地理解这个问题更需要信息。

我可以提供几个可以核实的检查点:

  1. where do you run this application? In compute emulator or on Windows Azure
  2. IF it is running into Compute Emulator have your setup firewall at SQL Azure to accept connection from your development machine and vice-versa if required.
  3. If this application is running in Windows Azure, have you modified the firewall policy
  4. Where ever you run this application, you must be able to prove first that a connection to SQL Azure is possible because application itself can not do this, you would have to setup the environment so connection to SQL Azure is working
  5. With Log4Net I always do two things:
    1. I always verify first that my Log4Net setting/code does work file using the local logging
    2. Once above is confirmed, I jump to next step and add code/configuration to change logging to other destination.
  6. If all of above are verified, then look for network trace where your application is running (compute Emulator or Windows Azure) for any network data towards SQL Azure server.
问题回答

利用日志4net和LAQ进行应用记录。 以下是一些尝试:

(1) 你的纽带应当这样看:

<connectionString value="data source=ServerName;initial catalog=DBName;integrated security=false;persist security info=True;User ID=SQLUsername;Password=SQLPassword" />

2) app4net。 内部。 贵网络的搜索部分应当有 De的关键。 组合,而不是记录4net部分。 e.g.

...
</configSections>
<appSettings>
  <add key="log4net.Internal.Debug" value="true"/>
</appSettings>
<log4net>
...

3) 日元内部假装电文向该系统书写。 诊断。 追踪系统。 在解决标识网配置问题时,我要通过在我的网页上添加以下内容,把微量产出改成一个文件。 净服务器程序可以写到档案中:

<system.diagnostics>
  <trace autoflush="true">
    <listeners>
      <add
        name="textWriterTraceListener"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="c:	emplog4net.txt" />
    </listeners>
  </trace>
</system.diagnostics>

我同意,AdoNetAppender在上文答复第2号中具体指明了这一联系时即行。 另外,如果你远离Solker数据库,则肯定会制定防火墙源IP规则,使你的IP地址能够连接到数据库。

In my quest to resolve this, I discovered that an Azure SQL table MUST have a CLUSTERED INDEX. Based on the standard log table, this is how it should look.

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,
CONSTRAINT [PK_Log] PRIMARY KEY CLUSTERED ([Id] ASC)
)




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签