Last active
August 29, 2015 13:56
-
-
Save lasandell/9230342 to your computer and use it in GitHub Desktop.
Comparison of custom log4net Layout class I wrote in C# versus its F# equivalent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GuidLayout : RawPropertyLayout | |
{ | |
public override object Format(LoggingEvent loggingEvent) | |
{ | |
var baseFormat = base.Format(loggingEvent); | |
if (baseFormat is Guid) | |
return baseFormat; | |
var guidString = baseFormat as string; | |
if (guidString != null) | |
{ | |
Guid guid; | |
if (Guid.TryParse(guidString, out guid)) | |
return guid; | |
} | |
return null; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type GuidLayout() = | |
inherit RawPropertyLayout() | |
override this.Format(loggingEvent) = | |
match base.Format(loggingEvent) with | |
| :? Guid as guid -> box guid | |
| :? string as guidString -> | |
match Guid.TryParse(guidString) with | |
| true, guid -> box guid | |
| _ -> null | |
| _ -> null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment