Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ion Cracea 12 posts 93 karma points
    Mar 06, 2020 @ 10:52
    Ion Cracea
    0

    Logging in Umbraco 8. The correct way ?

    Hi, This may be a stupid question but, anyway.

    I have a custom membership provider that implement certain membership provider methods. I'm trying to create log messages inside those methods. According to the doc, this should be enough:

    Logger.Info<MyApiController>("We are saying hello to {Name}", name);
    

    However, I can't find Logger in the Umbraco.Core.Logging namespace.or any other namespaces.

    Is there a way I can create logs from this file, do I have to create my own logger, what would the correct solution be for creating logs here.

    Thank you!

  • Kevin Jump 2342 posts 14869 karma points MVP 8x c-trib
    Mar 06, 2020 @ 11:40
    Kevin Jump
    100

    Hi,

    I think in the example Logger has been injected into the class - so in the wonderful world of dependency injection. the main constructor of the class will take either a ILogger of IProfilingLogger argument, and that is the logger.

    If for reasons you don't think you can use Dependency Injection (but do try), then you can access the Singleton version of the logger in Current.Logger

    (it is recommended you avoid the singleton for reasons)

  • Ion Cracea 12 posts 93 karma points
    Mar 06, 2020 @ 12:29
    Ion Cracea
    0

    Hi Kevin, Thank you for your reply.

    I can't use DI here as the MembershipProvider class is not built via container. I get this error when trying to do so: https://static.md/72d6943a5ee0c73e915cf96b1b57723d.png

    But instead, I've used

    Umbraco.Core.Composer.Current.Logger.Error
    

    This also shows the error in backoffice.

    I'm not sure if that is a good practice or if there is any better solution, please let me know if you are aware of any.

    Thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft