Last post Sep 16, 2013 11:21 AM by bbcompent1
Sep 13, 2013 02:00 PM|ramll|LINK
I am using log4net for the first time. I get Log4net dll from Nuget package in VS 2012.
My question is where will it log ? How can I access the logged error ?
Sep 13, 2013 02:19 PM|bbcompent1|LINK
"The file value can either be an absolute path like "c:\logs\log.txt" or a relative path which I believe is relative to the bin directory."
Sep 13, 2013 04:27 PM|ramll|LINK
Cant we store errors in our database using log4net ?
How can we check errors in that text file ? Isn't it difficult ?
Sep 16, 2013 11:19 AM|bbcompent1|LINK
Let me do some checking, there should be a way to log directly to the DB, even if its a direct sql statement doing an insert using the output from Log4Net.
Sep 16, 2013 11:21 AM|bbcompent1|LINK
Definitely doable. Take a look at this CodeProject example:
Here is the tricky one. This specific example writes to SQL, but you can write to just about any database you want using this pattern.
Note that the connectionType is basically a connection string, so modifying it is simple. The commandText specified is a simple query.
You can modify it to any type of INSERT query that you want (or Stored Procedure). Notice that each parameter is specified below and
mapped to a log4net variable. The size can be specified to limit the information placed into the parameter. This appender is a direct
copy from the log4net example. I take no credit for it. I simply use it as an example of what can be done.
Quick note: If you find that your ADO.NET appender is not working, check the bufferSize value. This value contains the number of log
statements that log4net will cache before writing them all to SQL. The example on the log4net website has a bufferSize of 100, which
means you will probably freak out in testing when nothing is working. Change the bufferSize value to 1 to make the logger write every
statement when it comes in.
For this example and more, go to the following URL: http://logging.apache.org/log4net/release/config-examples.html.