#if NETFRAMEWORK
using System.Web.Http;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Web.Mvc;
using Umbraco.Core.Services;
using Umbraco.Web.WebApi;
#else
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Cms.Web.Common.Attributes;
#endif
So i was going to try this approach on another project, but i have quite a few logging lines, through the code (it really helps to have logging in packages, for when people tell you they are having issues, but you do not have access to their site!).
So for example i will inject ILogger (from Umbraco.Core.Logging). into a service and call the logger.
now if i have shared code across a project it would be great if i could have the same logger lines in the code for both versions (and #ifdef around each log line seems fugly)
real questions are :
can i / should i go to the base serilog interface and use that logger which i am guessing is the same between v8 and v9 ?
should i look at wrapping the logging so the same call can be made in each version -and the diffrences are in a method somewhere else ?
is there some super neat trick i am missing that would make this bit super simpler ☺
I think I would look into making two different extension methods that are named equally and with the same params, except the ILogger instance.
Thereby it should even work with the same using statements. But would require you to inject the different ILogger types, in the ctor, but I guess the ctor is different anyway in most cases?
One other thought I had is what if we (meaning the Umbraco runtime) injected a custom Microsoft ILogger instance in the v8 version, so that in both versions you could use the Microsoft ILogger instance. The custom instance would handle logging in v8 as you would expect, and in v9 it would work with the native instance.
Logging in Umbraco 9 - anyway to share the calls with Umbraco 8
Hi,
I am looking at migrating a package i have on v8 and wondering if i can do some multi-targeting in the project so i have one code base ?
I have an example of this working for the linkedpages package. ( https://github.com/KevinJump/Our.Umbraco.LinkedPages/tree/dev/shared ) for a lot of not to "technical inside Umbraco stuff", you can get away with #ifdef blocks around using statements.
e.g the controller for that package has :
So i was going to try this approach on another project, but i have quite a few logging lines, through the code (it really helps to have logging in packages, for when people tell you they are having issues, but you do not have access to their site!).
So for example i will inject
ILogger
(fromUmbraco.Core.Logging
). into a service and call the logger.in v9 you inject
ILogger<MyService>
(from usingMicrosoft.Extensions.Logging
;) and the call isnow if i have shared code across a project it would be great if i could have the same logger lines in the code for both versions (and #ifdef around each log line seems fugly)
real questions are :
is there some super neat trick i am missing that would make this bit super simpler ☺
Hi Kevin..
I think I would look into making two different extension methods that are named equally and with the same params, except the ILogger instance.
Thereby it should even work with the same using statements. But would require you to inject the different ILogger types, in the ctor, but I guess the ctor is different anyway in most cases?
Extension methods are also used in this article about high performance logging: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/loggermessage?view=aspnetcore-5.0
That is very likely something we will look into in the CMS too, to improve logger performance.
BR/ Bjarke Berg
One other thought I had is what if we (meaning the Umbraco runtime) injected a custom Microsoft ILogger instance in the v8 version, so that in both versions you could use the Microsoft ILogger instance. The custom instance would handle logging in v8 as you would expect, and in v9 it would work with the native instance.
Sounds like a good idea..
I've opened a feature request at https://github.com/umbraco/Umbraco-CMS/issues/10196 to see if we can get this into v8.
is working on a reply...