Question : Unable to log a Guid Type into SQL Using log4net AdoNetAppender

Hi,

What is the correct appender syntax for logging a guid type to SQL Server? I am using the following snippet to log to SQL

            loggingEvent.Properties["UserId"] = System.Guid.NewGuid().ToString();
            logger.Logger.Log(loggingEvent);

but get the following error

log4net:ERROR [AdoNetAppender] Exception while writing to database
System.InvalidCastException: Failed to convert parameter value from a String to a Guid. ---> System.InvalidCastException: Invalid cast from 'System.String' to 'System.Guid'.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:

        
        
        
        
          
        
      

Answer : Unable to log a Guid Type into SQL Using log4net AdoNetAppender

Do not use System.Guid.NewGuid().ToString(), just System.Guid.NewGuid();
1:
2:
loggingEvent.Properties["UserId"] = System.Guid.NewGuid();
logger.Logger.Log(loggingEvent); 
Random Solutions  
 
programming4us programming4us