I am trying to write to my database the date of now with NLog and I have this error:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
I tried everything but nothing works for me and even when I print on the terminal the date has a correct format. I am using DateTime.Now so I don't really know.
Controller :
var modificationDate = new SqlDateTime(DateTime.Now);
// Créer un LogEventInfo
var logEvent = new LogEventInfo(NLog.LogLevel.Info, logger.Name, "Accès modifiés pour l'utilisateur {UserID}");
logEvent.Properties["UserID"] = userID;
logEvent.Properties["currentUser"] = currentUser;
logEvent.Properties["ModificationDate"] = modificationDate;
logEvent.Properties["UserGroups"] = string.Join(",", groups);
NLog.config :
<parameter name="@util" layout="${event-properties:UserID}" dbType="String" size="50" />
<parameter name="@modif_par" layout="${event-properties:currentUser}" dbType="String" size="50" />
<parameter name="@date_modif" layout="${longdate:universalTime=true}" dbType="datetime" />
<parameter name="@acces_modif" layout="${event-properties:UserGroups}" dbType="String" />
@date_modifparameter doesn't have anevent-propertiesin thelayout? Maybe that's why the date doesn't have a value?@date_modifis configured for universal time, but you are assigning it a value created for the local time viaDateTime.Now. You may wantDateTime.UtcNowinstead, or may want to change the definition. Of course, if you know the code is running on a machine configured where the local time is already universal time this is less important.throwConfigExceptions="true"and enable NLog InternalLogger when troubleshooting NLog.