Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to cast object of type 'Sentry.Log4Net.SentryAppender' to type 'log4net.Appender.IAppender' #3365

Open
khsd opened this issue May 14, 2024 · 4 comments
Labels
Bug Something isn't working log4net

Comments

@khsd
Copy link

khsd commented May 14, 2024

Package

Sentry.Log4net

.NET Flavor

.NET

.NET Version

4.8.0

OS

Windows

SDK Version

4.6.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. Added the following config to an existing log4net configuration running under Sitecore on .net 4.8
    <log4net>
      <appender name="SentryAppender" type="Sentry.Log4Net.SentryAppender, Sentry.Log4Net">
        <Dsn value="https://**************************************************************" />
        <!--Sends the log event Identity value as the user-->
        <SendIdentity value="true" />
        <Environment value="Test" />
        <bufferSize value="1"/>
        <threshold value="ERROR" />
      </appender>
      <root>
        <appender-ref ref="SentryAppender"/>
      </root>
    </log4net>

Expected Result

No error during initialization.

Actual Result

log4net: DOMConfigurator: Loading Appender [SentryAppender] type: [Sentry.Log4Net.SentryAppender, Sentry.Log4Net]
log4net:ERROR DOMConfigurator: Could not create Appender [SentryAppender] of type [Sentry.Log4Net.SentryAppender, Sentry.Log4Net]. Reported error follows.
System.InvalidCastException: Unable to cast object of type 'Sentry.Log4Net.SentryAppender' to type 'log4net.Appender.IAppender'.
   at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR DOMConfigurator: Appender named [SentryAppender] not found.
@bitsandfoxes
Copy link
Contributor

Hey @khsd, sorry to see you run into issues.
I'm not quite sure how to go about this. The SentryAppender inherits from AppenderSkeleton and I don't see where the requirement for log4net.Appender.IAppender comes from.
Would you be able to share a minimal repro with us?

@bitsandfoxes bitsandfoxes added Bug Something isn't working log4net labels May 14, 2024
@jamescrosswell
Copy link
Collaborator

I'm not quite sure how to go about this. The SentryAppender inherits from AppenderSkeleton and I don't see where the requirement for log4net.Appender.IAppender comes from.

AppenderSkeleton implements IAppender. I'm guessing log4net just needs any old IAppender and AppenderSkeleton is a quick way to wire one of these up without a bunch of boilerplate.

@khsd
Copy link
Author

khsd commented May 15, 2024

Log4net for my project is provided by Sitecore so it maybe this implementation that makes the error.
I don't think i can share a project since it would require a license for Sitecore.
I will try to debug this some more at this end and report my findings.

@jamescrosswell
Copy link
Collaborator

I will try to debug this some more at this end and report my findings.

Something that you might be able to test is whether you have the same issue if specifying the configuration in C# (rather than XML). If you don't, that would indicate a problem with the XML configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working log4net
Projects
Status: No status
Status: No status
Development

No branches or pull requests

3 participants