I'm trying to add a custom property which is a guid, but it gives me this error:
System.InvalidCastException: Failed to convert parameter value from a String to a Guid. ---> System.InvalidCastException: Invalid cast from 'System.String' to 'System.Guid'.
I specify this in the config:
<parameter>
<parameterName value="@id" />
<dbType value="Guid" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%X{id}" />
</layout>
</parameter>
The actual code (snippet) i use is this:
Guid guid = Guid.NewGuid();
if (defaultLogger.IsEnabledFor(level))
{
var loggingEvent = new LoggingEvent(ThisDeclaringType,
defaultLogger.Repository, defaultLogger.Name, level, message, exception);
loggingEvent.Properties["Id"] = guid;
Any help please? :) The id field in the database is defined as a uniqueidentifier NOT NULL, but it does not have the primary key contraint.
For your example the following should work:
<parameter>
<parameterName value="@Oid" />
<dbType value="Guid" />
<layout type="log4net.Layout.RawPropertyLayout">
<key value="Id" />
</layout>
</parameter>
Important is you rename @id to something else otherwise you will get Null values in database even if you try to insert strings,
And then use RawPropertyLayout to store, cus you do not need to do a convertion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With