TinyBlueRobots / Serilog.Sinks.ILogger

Serilog sink that writes to a Microsoft ILogger
The Unlicense
11 stars 3 forks source link

Azure Functions 2.0 #1

Open rhavlick opened 6 years ago

rhavlick commented 6 years ago

Hello,

Do you have an example of how this could be used in Azure Functions 2.0 where the ILogger is passed into the static function? (There is a lack of DI in Azure Functions 2.0 currently)

Thanks.

JonCanning commented 6 years ago
public static void Run(TimerInfo myTimer, Microsoft.Extensions.Logging.ILogger logger)
{
  var log = new LoggerConfiguration().WriteTo.ILogger(logger).CreateLogger();
  log.Information("Hello!");
}

Does that help?

rhavlick commented 6 years ago

Thanks Jon, sorry, I wasn't more descriptive, but is there a way to do something like: public static void Run(TimerInfo myTimer, Microsoft.Extensions.Logging.ILogger logger) { var log = new LoggerConfiguration().WriteTo.ILogger(logger).CreateLogger(); logger.LogInformation("Hello!"); }

I would like to use the existing ILogger, but just have it write to SeriLog.

Thanks

JonCanning commented 6 years ago

Sorry, I don't understand; Serilog writes to the ILogger and any other sinks you provide. In my case I write to the ILogger so I can see the output in the console, and to Loggly.

This sink behaves in the same way as the TraceWriter sink: https://www.nuget.org/packages/Serilog.Sinks.AzureWebJobsTraceWriter

IanGrainger commented 4 years ago

I think he wants to do the same as me, use ILogger, but use Serilog to customise how it outputs. I think the problem is that the ILogger isn't available when you setup Serilog in StartUp.