Cannot create instance of type 'Serilog.Formatting.ITextFormatter' because it is either abstract or an interface

See original GitHub issue

At runtime i have this error:

System.InvalidOperationException
  HResult=0x80131509
  Mensaje = Cannot create instance of type 'Serilog.Formatting.ITextFormatter' because it is either abstract or an interface.
  Origen = Microsoft.Extensions.Configuration.Binder
  Seguimiento de la pila:
   en Microsoft.Extensions.Configuration.ConfigurationBinder.CreateInstance(Type type)
   en Microsoft.Extensions.Configuration.ConfigurationBinder.BindInstance(Type type, Object instance, IConfiguration config, BinderOptions options)
   en Microsoft.Extensions.Configuration.ConfigurationBinder.Get(IConfiguration configuration, Type type, Action`1 configureOptions)
   en Microsoft.Extensions.Configuration.ConfigurationBinder.Get(IConfiguration configuration, Type type)
   en Serilog.Settings.Configuration.ObjectArgumentValue.ConvertTo(Type toType, ResolutionContext resolutionContext)
   en Serilog.Settings.Configuration.ConfigurationReader.<>c__DisplayClass21_2.<CallConfigurationMethods>b__3(<>f__AnonymousType9`2 <>h__TransparentIdentifier0)
   en System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
   en System.Linq.Enumerable.SelectListPartitionIterator`2.ToList()
   en Serilog.Settings.Configuration.ConfigurationReader.CallConfigurationMethods(ILookup`2 methods, IList`1 configurationMethods, Object receiver)
   en Serilog.Settings.Configuration.ConfigurationReader.ApplySinks(LoggerConfiguration loggerConfiguration)
   en Serilog.Settings.Configuration.ConfigurationReader.Configure(LoggerConfiguration loggerConfiguration)
   en Serilog.Configuration.LoggerSettingsConfiguration.Settings(ILoggerSettings settings)
   en Serilog.ConfigurationLoggerConfigurationExtensions.Configuration(LoggerSettingsConfiguration settingConfiguration, IConfiguration configuration, String sectionName, DependencyContext dependencyContext)

appsettings.json

  "Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Enrichers.ClientInfo", "Serilog.Expressions" ],
    "MinimumLevel": {
      "Default": "Verbose",
      "Override": {
        "Microsoft": "Verbose",
        "Microsoft.AspNetCore": "Verbose",
        "Microsoft.Hosting.Lifetime": "Verbose",
        "System": "Verbose"
      }
    },
    "WriteTo": [
      {
        "Name": "File",
        "Args": {
          "path": "%StoredFilesPath%\\serilog-Desarrollo-.json",
          "formatter": {
            "type": "Serilog.Templates.ExpressionTemplate, Serilog.Expressions",
            "template": "{ {T:ToString(@t, 'HH:mm:ss.fffffff'), L:coalesce({Information: 'INF', Warning: 'WRN', Error: 'ERR', Fatal: 'FTL', Verbose: 'VRB', Debug: 'DBG'}[@l], @l), SRC:if SourceContext <> 'Serilog.AspNetCore.RequestLoggingMiddleware' then SourceContext else undefined(), @m, EsBoot2:EsBoot(ClientAgent), EsBoot1:if Contains(ClientAgent, 'bot') then 'Si' else 'No', Pag:Concat(RequestScheme, '://', RequestHost, Resource), Ip:ClientIp, Idf:CorrelationId, EvId:EventId, IdMsgT:ToString(@i, 'X8'), @mt, ..@p, RequestScheme: undefined(), RequestHost: undefined(), Resource: undefined(), ClientIp: undefined(), CorrelationId: undefined(), EventId: undefined(), \r\n@x} }\r\n",
            "nameResolver": "PuedeSerBoot"
          },
          "rollingInterval": "Hour",
          "rollOnFileSizeLimit": true,
          "retainedFileCountLimit": null,
          "buffered": false,
          "flushToDiskInterval": 1,
          "shared": true
        }
      },
      {
        "Name": "Console"
      }
    ],
    "Enrich": [ "FromLogContext", "WithClientIp", "WithClientAgent" ],
    "Destructure": [
      {
        "Name": "ToMaximumDepth",
        "Args": { "maximumDestructuringDepth": 6 }
      },
      {
        "Name": "ToMaximumStringLength",
        "Args": { "maximumStringLength": 1000 }
      },
      {
        "Name": "ToMaximumCollectionCount",
        "Args": { "maximumCollectionCount": 20 }
      }
    ]
  },
   StaticMemberNameResolver myFunctions = new(typeof(PuedeSerBoot));
    CompiledExpression expr = SerilogExpression.Compile("EsBoot(ClientAgent)", null, myFunctions);

    Log.Logger = new LoggerConfiguration()
      .ReadFrom.Configuration(config, "Serilog")
      .CreateLogger(); //.CreateBootstrapLogger();`

Versions:

 <ItemGroup>
    <PackageReference Include="AspNetCoreRateLimit" Version="4.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
    <PackageReference Include="Serilog" Version="2.10.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
    <PackageReference Include="Serilog.Enrichers.ClientInfo" Version="1.1.4" />
    <PackageReference Include="Serilog.Expressions" Version="3.2.1" />
    <PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
    <PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
    <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
  </ItemGroup>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
skomis-mmcommented, Nov 22, 2021

Hi @FJGR65 , for the original question I think you need specify full type name for PuedeSerBoot:

"nameResolver": "[Namespace].PuedeSerBoot, [Assembly]"

(also, don’t forget to include it to the Using section)

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Serilog.Settings.Configuration is not working when it is ...
Formatting.ITextFormatter' because it is either abstract or an interface.' Here is code example that I am using to parse configuration:
Read more >
Serilog logging with .Net Core — Are we configuring it correctly?
It is very easy to set up but the question is, Are we doing it correctly? To start with Serilog with .net core,...
Read more >
Customized JSON formatting with Serilog
This post collects all kinds of JSON formatting examples using ExpressionTemplate , and I'll add to them as new questions come my way...
Read more >
How to Add logging to ASP.NET Core using Serilog - .NET6
Add Serilog to start logging to ASP.NET Core using Serilog with this easy step-by-step .NET Tutorial about logging using Serilog in .NET6.
Read more >
Using Serilog for Logging in ASP.NET Core
This article will help you add logging to your ASP.NET Core project using Serilog, and to configure it correctly.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found