Formato de hora NLog


¿Cómo escribo un layout para NLog que genera tiempo con milisegundos como este 11:32:08:123? Utilizo ${date:format=yyyy-MM-dd HH\:mm\:ss} pero necesito más precisión de tiempo en mis registros.

 35
Author: Julian, 2010-09-20

3 answers

${date:format=yyyy-MM-dd HH\:mm\:ss.fff}

De acuerdo con la documentación de NLog, puede usar la cadena de formato de fecha y hora C#.

Esta es una referencia bastante buena para cadenas de formato DateTime: http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm

 77
Author: matthughes404,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-18 08:25:17
${longdate}

Otra alternativa al formato sugerido por harriyott es usar el renderizador ${longdate}. Debería darte automáticamente la precisión que necesitas.

 11
Author: Ali,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-06 11:34:31

Otra solución alternativa es utilizar el formato ISO 8601 '1998-02-23T14:23:05.555'. Este formato es independiente del idioma del servidor sql.

${date:format=yyyy-MM-ddTHH\:mm\:ss.fff}
 5
Author: Fux,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-28 08:54:23