Suppress some exception logging in diagnostic toolkit configuration

michael.freidgeim's Avatar


27 Mar, 2013 08:21 PM

I need to suppress  some exception logging and I have 3 questions regarding diagnostic toolkit configuration

  1. Is order of  include/exclude essential?
    In example requested to apply LogAttribute to all methods , but not properties

         <LogAttribute   xmlns="clr-namespace:PostSharp.Toolkit.Diagnostics;assembly:PostSharp.Toolkit.Diagnostics" />
         <LogAttribute xmlns="clr-namespace:PostSharp.Toolkit.Diagnostics;assembly:PostSharp.Toolkit.Diagnostics" 
            AttributeTargetMembers="regex:get_.*|set_.*" />
     If I will put exclude row first, will result be the same? What are the rules about include/exclude priority?
  2. Can I distinct overloads in AttributeTargetMembers?
    E.g. If I have 2 overloads RedirectToNewResultsIfEnabled(int param1) and RedirectToNewResultsIfEnabled(string param1) is it possible in AttributeTargetMembers to specify one, but not another?

  3. How to exclude some types of exceptions in LogAttribute OnExceptionLevel?
    I am using LogAttribute to log exceptions
        < LogAttribute xmlns="clr-namespace:PostSharp.Toolkit.Diagnostics;assembly:PostSharp.Toolkit.Diagnostics" OnExceptionLevel="Warning"   OnExceptionOptions =" IncludeParameterValue"
                          AttributeTargetAssemblies="MyAssembly"   AttributeTargetTypes="MyAssembly.*"    AttributeTargetMembers="*"
    It logs all exceptions, including ThreadAbortException, that is used in normal Redirect processing 
    HttpContext.Current.Response.Write(redirectUrl);     HttpContext.Current.Response.End();
    and should NOT be  logged as a warning.

What is the best way to address the issue? Should I derive custom LogAttributeExcludingSomeExceptions from normal LogAttribute? Will you consider to extend PostSharp.Toolkit.Diagnostics.LogAttribute to support optional ExcludeExceptions property in a future releas? 

  1. Support Staff 1 Posted by sharpcrafters on 28 Mar, 2013 10:32 AM

    sharpcrafters's Avatar


    Ad. 1 The attribute with exclude set to true effects only what was processed to the point of occurrence of the exclude i.e. exclude will effect only attributes occurring prior to exclude.
    Ad 2. For now it is only possible to match method name so there is no way of distinguishing overloads.
    Ad 3. In current version of Postsharp.Patterns it is not possible to exclude some types of exceptions. Due to the way Diagnostic is implemented it is also not possible to change this behavior through simply inheriting from LogAttribute. We will evaluate your request of filtering exception types.



  2. 2 Posted by kenti on 07 Nov, 2014 04:58 PM

    kenti's Avatar

    Has anything been done for #3 above? I want to log exceptions, but not ThreadAbortException because that is thrown on a redirect.

  3. Support Staff 3 Posted by sharpcrafters on 11 Nov, 2014 01:50 PM

    sharpcrafters's Avatar


    No, filtering based on the exception types has not been implemented yet in Diagnostics Library. We have already planned to work on improving Diagnostics Pattern Library, and this item may be touched as well. We'll let you know as soon as there is any progress.


  4. Support Staff 4 Posted by sharpcrafters on 13 Nov, 2014 06:35 PM

    sharpcrafters's Avatar


    The request to filter logged exceptions based on the exception type has been added to the user voice list -

    Please vote on this request if you're interested to see it implemented.


Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac