What is the best practice for registering with Umbraco?

I noticed that there are two ways to write magazines in Umbraco. One way is to use the LogHelper class, and the other is to directly use the methods of the instance obtained using the log4net.LogManager.GetLogger method. Needless to say, LogHelper also uses log4net.

I added a custom logging application, setting the appender file to a different file from the default, and tried in both directions, and noticed that the results in the log are more or less the same. The LogHelper entry is as follows:

ERROR ProjectName.Controllers.Backoffice.DataController - [P4876 / T1 / D2] Test

while the entry that log4net creates looks like this:

ERROR ProjectName.Controllers.Backoffice.DataController - Test

However, when I looked for registration messages in Umbraco, I often found examples of using log4net directly, instead of using the LogHelper class provided by Umbraco CMS.

Basically, are there any good reasons why developers should use one path instead of another, or just a matter of preference for using library methods instead of using the helper class provided by CMS (or vice versa (helper in front of the library)?

+5
source share
2 answers

LogHelper is a convenient shell for logging - it is part of the logging structure with the Umbraco.Core.Logging.ILogger interface in it. The default implementation is log4net, but there is also an internal class DebugDiagnosticsLogger that outputs everything via Debug.WriteLine .

Typically, if you are developing Umbraco libraries, then LogHelper is the way to go.

+14
source

Perhaps LogHelper is designed in such a way that developers do not have to worry about which specific logging provider is used in Umbraco (log4net, Elmah, whatever). Therefore, theoretically, this can lead to insignificant overhead, but it is easier to use.

I don't think there is a real “best practice”, but I would use LogHelper :-)

+3
source

Source: https://habr.com/ru/post/1232451/


All Articles