Copied to clipboard

Flag this post as spam?

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


  • Oskar 5 posts 75 karma points
    Nov 01, 2019 @ 16:25
    Oskar
    0

    Good morning, I am begginer using Umbraco, I would like knowing about logging in umbraco. I want to do custom logging for my site... what things should I consider for that? .. I hope any one can help me.. Thanks.

  • Marc Goodson 1154 posts 7677 karma points MVP 4x c-trib
    Nov 02, 2019 @ 21:02
    Marc Goodson
    0

    Hi Oscar

    There is a good introduction here to serilog which Umbraco has baked in:

    https://our.umbraco.com/Documentation/Getting-Started/Code/Debugging/Logging/

    Particularly how you can write your own custom messages to the log.

    Regards

    Marc

  • Oskar 5 posts 75 karma points
    Nov 05, 2019 @ 14:54
    Oskar
    0

    Thanks Marc.

  • Oskar 5 posts 75 karma points
    Nov 05, 2019 @ 15:06
    Oskar
    0

    Good morning All:

    I created a class and one method with this code :

    using Serilog; using Serilog.Sinks.Splunk;

    Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.EventCollector .WriteTo.File(.....) .CreateLogger();


    I want to use it in my controllers and I am doing this:

    using Umbraco.Core.Logging;
    
    public class UmbracoDefaultController : RenderMvcController
    {
        private readonly ILogger _logger;
    
        public UmbracoDefaultController(ILogger logger)
        {
            _logger = logger;
        }
    
       public ActionResult Index(BasicViewModel viewModel)
        {
             var testname = "Hello first test - 01";
             Logger.Info<UmbracoDefaultController>("Begin - {testname} ", testname); 
        }
    }
    

    Is it ok?...or Am I working in wrong way?.. Is there dependency injection? if there is no , How I could work using dependency injection using injectlight from umbraco?

    I hope someone can help me.

  • Craig100 1032 posts 2271 karma points c-trib
    3 days ago
    Craig100
    0

    Hi Oskar,

    Did you get your example to work? When I use the docs like you have I just get "Logger does not contain a definition for Info". Which is true, it's "information" but then the syntax for the rest seems wrong.

    I'm trying to use it in my own class in a V8.6.1 .core project (as opposed to .web).

    Any advice would be great.

    / Craig

  • Nik 1267 posts 5300 karma points MVP 2x c-trib
    3 days ago
    Nik
    0

    Hi Craig,

    Are you trying to create your own logging or use the Core Umbraco logging facilities?

    If it is the latter and you are taking advantage of Dependency Injection, if you inject ILogger or IProfilingLogger (both are in the Umbraco.Core.Logging name space) then you can access them and log things as and when you need.

    Both have .Info, .Warning, and .Error methods on them where you can pass the relevant information to the methods to be logged.

    Nik

  • Craig100 1032 posts 2271 karma points c-trib
    3 days ago
    Craig100
    0

    Hi Nik,

    Thanks for your reply. I'm trying to use the Core Umbraco logging facilities. Although I've read and read about DI and understand what it's meant to do, I haven't yet managed to get my head around the syntax, it just doesn't say anything to me.

    The class is "using Umbraco.Core.Logging;" but on Logger.Info<ImportProperties>("Error Saving Property ID: {PropertyId}", apiProperty.property_ID); I just get "Logger does not exist in the current context". Do I "new" something or what is the syntax to DI it? It's so confusing.

    If I use the DI syntax from the Docs then I get "Logger does not contain a definition for Info".

    I'm "just" updating a class called by an API from V7 to V8 ;)

    The V7 code which worked was LogHelper.Error(MethodBase.GetCurrentMethod().DeclaringType, "Error Saving Property ID: " + property.Property_ID, ex);

    /Craig

Please Sign in or register to post replies

Write your reply to:

Draft