I have created a .Net class library (4.6.2) and created serilog implementation which is called by other interfaces such as console app. Now when I use File sink type, the logs are getting written to the files but with MSSQL sink, its not doing so.
The log tables are getting created with column options as provided with autoCreateTable options
ILogger logger = new LoggerConfiguration()
.WriteTo.MSSqlServer(connectionString,
tableName,
autoCreateSqlTable: autoCreateSqlTable,
restrictedToMinimumLevel: LogEventLevel.Verbose,
columnOptions: GetSQLSinkColumnOptions(),
batchPostingLimit: batchPostingLimit)
.CreateLogger();
I have else enabled selflogging of serilog but no exceptions are displayed. Not found any helpful solution for the same.
The log table is however getting generated. I have checked the permissions for the user and that is also having the correct permissions.
Below is the snap shot of the code.
public static class GenericLogger
{
private static ILogger _usageLogger;
private static ILogger _errorLogger;
static GenericLogger()
{
var logTypes = LogConfigurationHelper.GetLogTypes();
if (logTypes != null && logTypes.Count > 0)
{
foreach (var logType in logTypes)
{
ConfigureLogger(logType.Id); // Intitalizes logs based on
//configuration.
}
}
Serilog.Debugging.SelfLog.Enable(msg =>
{
Debug.Print(msg);
Debugger.Break();
});
}
///The write log function
///
public static void WriteError(LogDetail infoToLog)
{
if (infoToLog.Exception != null)
{
infoToLog.Message = GetMessageFromException(infoToLog.Exception);
}
_errorLogger.Write(LogEventLevel.Information,
"{Timestamp}{Product}{Layer}{Location}{Message}" +
"{Hostname}{UserId}{UserName}{Exception}{ElapsedMilliseconds}" +
"{CorrelationId}{CustomException}{AdditionalInfo}",
infoToLog.TimeStamp, infoToLog.Product, infoToLog.Layer, infoToLog.Location, infoToLog.Message,
infoToLog.Hostname, infoToLog.UserId, infoToLog.UserName, infoToLog.Exception?.ToCustomString(),
infoToLog.ElapsedMilliseconds, infoToLog.CorrelationId, infoToLog.CustomException,
infoToLog.AdditionalInfo);
// To add ((IDisposable) _errrorLog).Dispose();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…