Solved

Exception in Log4Net

Posted on 2016-11-10
1
32 Views
Last Modified: 2016-11-11
I need to log all stack of my exceptions using log4net.

<appender name="RollingFileErro" type="log4net.Appender.RollingFileAppender">
    <file value="C:\LOGS\Erro.log" />
    <appendToFile value="true" />
    <maximumFileSize value="500KB" />
    <maxSizeRollBackups value="2" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %level %logger - %message%newline" />
    </layout>
  </appender>

Open in new window


How can I log all stack of my exceptions?
0
Comment
Question by:berechit
1 Comment
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 41883466
You need to catch your exceptions and log it..

Take a look at the examples folder:

try
{
	Bar();
}
catch(Exception ex)
{
	// Log an error with an exception
	log.Error("Exception thrown from method Bar", ex);
}

Open in new window


The Error() method appends the stack trace.

When using PatternLayout Class, then use %stacktrace or %stacktracedetail in your format string.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question