Closed danammeansbear closed 11 months ago
Hi! I can't spot anything obvious in your example above. Checking SelfLog would be the way to go, if you're still digging into this. Closing as stale, but if you still need help, tagging with serilog
on Stack Overflow will get the right eyes on it 👍
I am trying to send the logs that are being logged in my log file over to my email address.
The logging currently send to a file but now I need it to send to my email and I am not sure what I am doing wrong? I have pasted the code below
` public static class SerilogCustomEmailExtension { const string DefaultOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";
`// "path": "C:/somedirectory/logs/website.log", "Serilog": { "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Email", "SomeFileName" ], "MinimumLevel": { "Default": "Debug", "Override": { "Microsoft": "Warning", "System": "Warning" } },
}` I have the above in my appsettings.json
`public class Program { public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .Enrich.With(new ThreadIdEnricher()) .WriteTo.File("C:/someDirectory/website.log", outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}") .WriteTo.Console( outputTemplate: "{Timestamp:HH:mm} [{Level}] ({ThreadId}) {Message}{NewLine}{Exception}") .WriteTo.Email(new EmailConnectionInfo { FromEmail = "noreply@email.com", ToEmail = "some@email.com", MailServer = "someEmailServer.com", //NetworkCredentials = new NetworkCredential //{ // UserName = appConfigs.Logger.EmailSettings.Username, // Password = appConfigs.Logger.EmailSettings.Password //}, EnableSsl = true, Port = 25, EmailSubject = "Requests Error" }, outputTemplate: "[{Timestamp:HH:mm:ss.fff} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}", batchPostingLimit: 10 , restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose ) .CreateLogger();