locked
Log4net RRS feed

  • Question

  • User1655374113 posted

    Hello,

    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 ?

    TIA

    Friday, September 13, 2013 2:00 PM

Answers

  • User-718146471 posted

    Definitely doable. Take a look at this CodeProject example:

     

    http://www.codeproject.com/Articles/140911/log4net-Tutorial

     

    ADO.NET Appender
    
    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 16, 2013 11:21 AM

All replies

  • User-718146471 posted

    "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."

     

    http://stackoverflow.com/questions/2815940/where-will-log4net-create-this-log-file

    Friday, September 13, 2013 2:19 PM
  • User1655374113 posted

    Cant we store errors in our database using log4net ?

    How can we check errors in that text file ? Isn't it difficult ?

    Friday, September 13, 2013 4:27 PM
  • User-718146471 posted

    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.

    Monday, September 16, 2013 11:19 AM
  • User-718146471 posted

    Definitely doable. Take a look at this CodeProject example:

     

    http://www.codeproject.com/Articles/140911/log4net-Tutorial

     

    ADO.NET Appender
    
    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 16, 2013 11:21 AM