Question

I'm using Serilog from within my website & web API all good.

Now I want to use Serilog from within WCF.

But when I new up a LoggerConfiguration and create a logger from within WCF, the logging doesn't seem to work? Eg nothing is being output to the text file.

var seriLog = new LoggerConfiguration()
    .WriteTo.File(@"C:\Serilogs\myapp.txt")
    .CreateLogger();

seriLog.Debug("log message");

Ultimately I want to write to Seq from within the WCF service.

What am I missing or doing wrong?

Has anyone got some working code samples of how this would be done?

Are there tricks to using the Serilog/Seq stack from within WCF?

Was it helpful?

Solution

There are a couple of things to that come to mind-

First, is the setup code here being executed only once, i.e. at application startup, so there is exactly one logger pointing to the text file? Only one instance of the logger can use the file at a time.

Next, is the process running with permission to access the file?

Last, is the file open e.g. in Notepad or another app that might have it locked?

If none of these spark any ideas, you can set up Serilog's self-log before configuring the logger:

SelfLog.Out = Console.Error;

This should get shown in the VS debugger, so if Serilog's catching and suppressing any exceptions you should see them.

If you can't run it in a debugger, try:

SelfLog.Out = File.OpenText(@"C:\loglog.txt");

Sometimes I find running the app under the debugger with "Break on all exceptions" enabled can be a quick way to get to the bottom of it, too (Ctrl-D,E -> CLR Exceptions [x] Thrown, [x] Unhandled).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top