• Share
    • Twitter
    • LinkedIn
    • Facebook
    • Email
  • Feedback
  • Edit
Show / Hide Table of Contents

SuperOffice.Serilog

Some tooltip text!
• 2 minutes to read
 • 2 minutes to read

The benefit of using the ILogger framework is that other systems can be plugged in, to allow logs to flow to lots of other places than just a text file. The log source (NetServer) is decoupled from the log sinks (text files, databases, cloud services).

Serilog is one of several logging frameworks that support the general ILogger API.

The SuperOffice.Serilog.dll is a thin wrapper around the Serilog logger. The wrapper handles setup and configuration.

public ILoggerProvider CreateLoggerProvider()
{
  string serilogConfig = FindSerilogConfigFile("serilog.json");
  serilogConfig = serilogConfig ?? FindSerilogConfigFile("appsettings.json");
  if (File.Exists(serilogConfig))
    return CreateLogProviderFromConfigFile(serilogConfig);
  return null;
}
  1. It looks for a serilog.json file in the current and parent directories.
  2. If nothing is found, then it looks for an appsettings.json file.
  3. If no config file is found, then we don't use Serilog.
  4. If we do find a Json config file, we can read it and set up the Serilog configuration pipeline:
ILoggerProvider CreateLogProviderFromConfigFile(string serilogConfigFilePath)
{
  var configuration = new ConfigurationBuilder()
    .SetBasePath(Path.GetDirectoryName(serilogConfigFilePath))
    .AddJsonFile(Path.GetFileName(serilogConfigFilePath))
    .Build();
  var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
  Log.Logger = logger;
  var provider = new SerilogLoggerProvider(logger);
  return provider;
}
Note

You need to create the serilog.json file and restart CRM Web if you switch from standard NetServer logging to Serilog.

Files to deploy

Don't want logging via Serilog? Remove the following DLLs:

  • SuperOffice.Serilog.dll
  • Serilog.dll
  • Serilog.Extensions.Logging.dll
  • Serilog.Settings.Configuration.dll
  • Serilog.Sinks.Debug.dll
  • Serilog.Sinks.File.dll
In This Article
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top