Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

.net core - serilog not creating log files

we are using the following piece of serilog code which writes events to console and file, the file and console logging works fine on my machine, but in the other developers machine console logging works but the file logging does not work and to add to the weirdness the"logs" folder gets created though. Is there any extra setup that needs to be done ?

   public static void SetupLogger()
        {
            //var outputTemplate =   "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}";
            var outputTemplate = "[{Level:u3}] {Message:lj}{NewLine}{Exception}";

            // Logger  
            //var outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u4}] | {Message:l}{NewLine}{Exception}";
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                .WriteTo.Console(outputTemplate: outputTemplate, theme:SystemConsoleTheme.Literate,restrictedToMinimumLevel:LogEventLevel.Information)
                .WriteTo.File($"logs/log-{DateTime.Now:yyyy-MM-dd_HH:mm:ss.fff}.log")              
                .CreateLogger();

        }
question from:https://stackoverflow.com/questions/65950440/serilog-not-creating-log-files

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The first step when troubleshooting any issue with Serilog is to turn on the SelfLog and see if there are any exceptions being caught. The error messages might give you a clue of what's the problem.

Serilog.Debugging.SelfLog.Enable(s => Console.WriteLine($"Internal Error with Serilog: {s}"));

Alternatively, if you didn't have a Console Window, you could also use a Notepad window to inspect the SelfLog.


Anyway, are the machines where it doesn't work running Windows? I ask because looking at your code, I wouldn't expect it to work on Windows because you're saving the file with : (colon) in the name which is not a valid character for file names in Windows.

invalid characters for files on Windows


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...