Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 830183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:00:12+00:00 2026-05-15T04:00:12+00:00

If an exception occurs in my MessageHandler I want to write the exception details

  • 0

If an exception occurs in my MessageHandler I want to write the exception details to my database.
How do I do this?

Obviously, I cant just catch the exception, write to database, and rethrow it since NSB rollbacks all changes. (IsTransactional is set to true)

I tried adding logging functionality in a seperate handler, which I caledl using SendLocal if an exception occured, but this does not work:

public void Handle(MessageItem message)
{
    try
    {
        DoWork();
    }
    catch(Exception exc)
    {
        Bus.SendLocal(new ExceptionMessage(exc.Message));
        throw;
    }
}

I also tried using Log4Net with a custom appender, but this also rolled back.

Configure.With()
.Log4Net<DatabaseAppender>(a => a.Log = "Log")

appender:

public class DatabaseAppender : log4net.Appender.AppenderSkeleton
{
    public string Log { get; set; }

    protected override void Append(log4net.Core.LoggingEvent loggingEvent)
    {
        if (loggingEvent.ExceptionObject != null)
            WriteToDatabase(loggingEvent.ExceptionObject);
    }
}

Is there anyway to log unhandled exceptions in the messagehandler when IsTransactional is true?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:00:12+00:00Added an answer on May 15, 2026 at 4:00 am

    I recommend to configure appenders with a configuration file and not in code. This way whoever operates your software can decide how stuff should be logged. The standard AdoNetAppender has the following configuration switch:

    <param name="UseTransactions" value="False" />
    

    I think this would work the way you want. If you really want to use your own appender you can either check in log4net source code how they do it. They probably use the TransactionScope class with the TransactionScopeOption.Suppress option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When an unexpected exception occurs in your program (in the debugger). Sometimes you just
Whenever an unhandled exception occurs on our site, I want to: Send a notification
How to catch exception in the main thread if the exception occurs in the
I am trying to open a SQLConnection and this exception occurs: Description: The application
any generic way to trace/log values of all local variables when an exception occurs
Often, I found OutOfMemoryException on IBM Websphere Application Server. I think this exception occur
Exception Thrown: System.ComponentModel.ReflectPropertyDescriptor is not marked as Serializable Does this mean I missed marking
This exception peppers our production catalina logs on a simple 'getParameter()' call. WARNING: Parameters:
when an exception occurs that a method is unable to handle - does the
When an exception occurs in Python, can you inspect the stack? Can you determine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.