Logging to elmah.io from Logary
Logary is a semantic logging framework like Serilog and Microsoft Semantic Logging. Combining semantic logs with elmah.io is a perfect fit since elmah.io has been designed with semantics from the ground up.
In this tutorial, we’ll add Logary to a Console application, but the process is almost identical to other project types. Create a new console application and add the elmah.io target for Logary:
Install-Package Logary.Targets.ElmahIO
dotnet add package Logary.Targets.ElmahIO
<PackageReference Include="Logary.Targets.ElmahIO" Version="5.*" />
paket add Logary.Targets.ElmahIO
Configuration in F#
Configure elmah.io just like you would any normal target:
withTargets [
// ...
ElmahIO.create { logId = Guid.Parse "LOG_ID"; apiKey = "API_KEY" } "elmah.io"
] >>
withRules [
// ...
Rule.createForTarget "elmah.io"
]
where LOG_ID
is the id of your log (Where is my log ID?).
Configuration in C#
Configuration in C# is just as easy:
.Target<ElmahIO.Builder>(
"elmah.io",
conf => conf.Target.SendTo(logId: "LOG_ID", apiKey: "API_KEY"))
where API_KEY
is your API key and LOG_ID
is the ID of your log.
Logging
To start logging messages to elmah.io, you can use the following F# code:
let logger = logary.getLogger (PointName [| "Logary"; "Samples"; "main" |])
Message.event Info "User logged in"
|> Message.setField "userName" "haf"
|> Logger.logSimple logger
or in C#:
var logger = logary.GetLogger("Logary.CSharpExample");
logger.LogEventFormat(LogLevel.Fatal, "Unhandled {exception}!", e);
This article was brought to you by the elmah.io team. elmah.io is the best error management system for .NET web applications. We monitor your website, alert you when errors start happening, and help you fix errors fast.
See how we can help you monitor your website for crashes Monitor your website