1
votes

adding nlog to .net core 3.0 application results in

'IServiceCollection' does not contain a definition for 'ConfigureLoggerService' and no accessible extension method 'ConfigureLoggerService' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

for Nuget I have

NLog.Extensions.Logging v1.6.1
NLog.Web.AspNetCore v4.9.0

in startup.cs

 public Startup(IConfiguration config)
        {
            LogManager.LoadConfiguration(String.Concat(Directory.GetCurrentDirectory(), "/nlog.config"));
            Configuration = config;
        }

public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(IISDefaults.AuthenticationScheme);
            services.AddMvc();
            services.AddTransient<ICwopaAgencyFileRepository, CwopaAgencyFileRepository>();
            services.AddTransient<ICurrentUserRepository, CurrentUserRepository>();
            services.AddTransient<IUserRepository, UserRepository>();
            services.AddTransient<IRevenueReceivedRepository, RevenueReceivedRepository>();
            services.AddTransient<ILesseeRepository, LesseeRepository>();
            services.AddTransient<ITractLesseeJunctionRepository, TractLesseeJunctionRepository>();
            services.AddTransient<IPadRepository, PadRepository>();
            services.AddTransient<IWellRepository, WellRepository>();
            services.AddTransient<IWellOperarationRepository, WellOperationRepository>();
            services.AddTransient<IRoyaltyRepository, RoyaltyRepository>();
            services.AddTransient<IRoyaltyAdjustmentCardViewModelRepository, RoyaltyAdjustmentCardViewModelRepository>();
            services.AddSingleton<ILoggerManager, LoggerService>();
            string conString = Configuration["ConnectionStrings:DefaultConnection"];
            services.AddDbContext<DataContext>(options =>
                options.UseSqlServer(conString));
            services.ConfigureLoggerService();
            services.AddMvc(option => option.EnableEndpointRouting = false);
            services.AddMemoryCache();
            services.AddSession();
        }

here is my csproj file

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup Label="Globals">
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
    <PackageReference Include="NLog" Version="4.6.8" />
    <PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
    <PackageReference Include="NLog.Web.AspNetCore" Version="4.9.0" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Migrations\" />
  </ItemGroup>

</Project>
1
do you have the right namespaces included?Daniel A. White
Do you have a main NLog package? It is a part of NLog.Extensions.Logging, but their GitHub says about NLog package. Please, share your csproj filePavel Anikhouski
just installed it, and it did not helpBryan Dellinger
I included my csproj fileBryan Dellinger
ConfigureLoggerService is not a method from NLog. Think you are using some broken tutorial. Try look here instead: github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-3Rolf Kristensen

1 Answers

4
votes

if you're following this tutorial, don't forget add this method extension

public static void ConfigureLoggerService(this IServiceCollection services)
{
    services.AddSingleton<ILoggerManager, LoggerManager>();
}

because you're calling it in this line

services.ConfigureLoggerService();

Also, you can considere removing it, because you're registering this service LoggerService with the interface ILoggerManager.