ayoub
ayoub

Reputation: 93

How to get logs data from the Log table using log4net library?

I implemented Log4Net with SQL Server Connection.

My issue is I can't see the logs data in the Log table until I stop IIS Express from running.

It seems weird for me, because I don't see the data right away when I click on my link. Basically I should see the log data in the Log table when I click on the link without stopping IIS from running.

(The database is hosted remotely an I am using C#)

Any Suggestions? Thanks!!

Upvotes: 0

Views: 266

Answers (1)

Cinchoo
Cinchoo

Reputation: 6332

AdoNetAppender uses buffering model to deliver the messages to underlying sources. Main reason why they did that way is to improve performance by not creating and commiting multiple sql transaction as opposed to one.

As per doc,

This appender uses a buffer to store logging events before delivering them. A triggering event causes the whole buffer to be send to the remote sink. If the buffer overruns before a triggering event then logging events could be lost. Set Lossy to false to prevent logging events from being lost.

UPDATE:

You can set the buffer size to something >= 1

<appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
      <connectionStringName value="DefaultConnection" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
      <useTransactions value="false" />
      <bufferSize value="1" />

Hope this helps.

Upvotes: 1

Related Questions