Regarding using logging in any component:
Adding logging to a component in your application is done by requesting either an ILoggerFactory
or an ILogger<T>
via Dependency Injection. If an ILoggerFactory
is requested, a logger must be created using its CreateLogger
method.
If your CustomClass
is a data container (DTO class), it should not know about logging, but just contain data.
For other classes with names like "Service" , "Provider", "Handler" and so on, the best practices is to resolve instances using dependency injection. In general, you should use DI wherever it is possible, as it’s a technique for achieving loose coupling between objects and their collaborators or dependencies. For more information, the following question might be interesting: Should I use Dependency Injection or static factories?
So simply add ILogger<CustomClass>
to its constructor (actually the same way, as you do for controllers), as .NET Core supports only constructor injection by default:
public class CustomClass
{
private readonly ILogger _logger;
public CustomClass(ILogger<CustomClass> logger)
{
_logger = logger;
}
}
ASP.NET Core’s built-in dependency injection container will automatically resolved transient dependencies. So if your controller has class A
as a dependency that uses class B
where you want to log something, your code can be something like this:
public class MyController
{
public MyController(ClassA classA)
{ ... }
}
public class ClassA
{
public ClassA(ClassB classB)
{ ... }
}
public class ClassB
{
private readonly ILogger _logger;
public ClassB(ILogger<ClassB> logger)
{
_logger = logger;
}
public void DoSomethingWithLogging()
{
// use _logger
}
}
Note that you also need to register the dependencies in Startup
using IServiceCollection.Add…
methods:
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddTransient<ClassB>();
services.AddTransient<ClassA>();
}
Built-in logging support means that .NET Core out of the box knows about and is using built-in abstractions for logging. This is mainly done by ILoggerFactory
and ILoggerProvider
interfaces.
/// <summary>
/// Represents a type used to configure the logging system and create instances of <see cref="ILogger"/> from
/// the registered <see cref="ILoggerProvider"/>s.
/// </summary>
public interface ILoggerFactory : IDisposable
// <summary>
/// Represents a type that can create instances of <see cref="ILogger"/>.
/// </summary>
public interface ILoggerProvider : IDisposable
Using your own ILoggerProvider
implementation, you can add your own logger that can do whatever you want. You can check the NLog logger implementation as working example.
And thanks to ILoggerFactory
, you can simply configure your Logger for project-specific purposes:
To configure logging in your ASP.NET Core application, you should resolve ILoggerFactory
in the Configure
method of your Startup
class. ASP.NET Core will automatically provide an instance of ILoggerFactory
using Dependency Injection when you add a parameter of this type to the Configure
method.
Best Answer
This is a known issue. Follow issue 22102 in the WebKit bug tracker (“
-webkit-box-shadow
causes awful scroll/resize/redraw performance”) to get notified when it’s fixed.Note that the box shadow in your example has a very large radius, which makes it worse. This explains why it might seem to work on other sites — they’re just using smaller radii.