Open Closed

How to implement Serilog in ANZ platform #11018


0
SRTMDEV created

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? 11.0.0
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? .net core

Hello Team,

We would like to implement Serilog with Azure Log Analytics in ANZ. Can you guide us which Serilog library compatible with ANZ and where we can implment the changes to applicable in all ANZ project.

Thanks, SRTMDEV


4 Answer(s)
  • 0
    ismcagdas created
    Support Team

    Hi,

    You can use this package https://www.nuget.org/packages/Castle.Core-Serilog and configure it in the Startup.cs file as shown below;

    options.IocManager.IocContainer.AddFacility<LoggingFacility>(
                        f => f.LogUsing(new SerilogFactory(config))
                    );
    

    instead of

    options.IocManager.IocContainer.AddFacility<LoggingFacility>(
                        f => f.UseAbpLog4Net().WithConfig(_hostingEnvironment.IsDevelopment()
                            ? "log4net.config"
                            : "log4net.Production.config")
                    );
    

    A sample config would be something like this;

     var config = new LoggerConfiguration()
                    .Enrich.WithProperty("ApplicationName", Assembly.GetExecutingAssembly().GetName().Name)
                    .WriteTo.MSSqlServer("Serilog", "Logs", columnOptions:columnOptions)
                    .ReadFrom.AppSettings()
                    .CreateLogger();
    
  • 0
    SRTMDEV created

    Hello Team,

    Thanks you so much for really valued ans. This really help us to get started to implement Serilog. Now we have one requirment where on each log we want to write current TenantId and UserId in seperate columns which help us to analyze log for each tenant.

  • 0
    ismcagdas created
    Support Team

    Hi @SRTMDEV

    We are not much experienced with Serilog. Maybe you can find how to do this on Serilog's documentation by using its LoggerConfiguration.

  • 0
    marble68 created

    By the way, this package doesn't work with 11.0.

    Just adding the package to the project causes it throw an error in startup.

    To recreate:

    Add the aforementioned package: Castle.Core-Serilog Add to Public, MVC, Host, and Migrator, just like log4net. Run - You'll get the following error:

    System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'Abp.Dependency.IocManager' threw an exception. Source=Abp StackTrace: at Abp.AbpBootstrapperOptions..ctor() at Abp.AbpBootstrapper..ctor(Type startupModule, Action1 optionsAction) at Abp.AbpBootstrapper.Create[TStartupModule](Action1 optionsAction) at Abp.AspNetCore.AbpServiceCollectionExtensions.AddAbpBootstrapper[TStartupModule](IServiceCollection services, Action1 optionsAction) at Abp.AspNetCore.AbpServiceCollectionExtensions.AddAbp[TStartupModule](IServiceCollection services, Action1 optionsAction, Boolean removeConventionalInterceptors) at inzibackend.Web.Startup.Startup.ConfigureServices(IServiceCollection services) in R:\Surpathv2\src\inzibackend.Web.Mvc\Startup\Startup.cs:line 201 at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection) at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder1.<>c__DisplayClass15_0.<BuildStartupServicesFilterPipeline>g__RunPipeline|0(IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services) at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass14_0.

    This exception was originally thrown at this call stack: [External Code]

    Inner Exception 1: TypeLoadException: Could not load type 'Castle.Core.Pair`2' from assembly 'Castle.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc'.