Suppose you're measuring values coming from a car. This is what that could look like:
Logary's file target is primarily geared towards systems that are running on single machines as it prints a human-readable format, rather than a machine- readable one.
The default configuration of the file target rotates log files greater than 200 MiB and deletes log files when the configured folder size is larger than 3 GiB.
Folders that don't exist when the target starts are automatically created on target start-up in the current service's security context. Should the calls to create the folder fail, the target is never started, but will restart continuously like any ther Logary target.
let fileConf =
{ File.FileConf.create logDir (Naming ("{service}-{host}-{datetime}", "log")) }
// ... withTargets [
File.create fileConf "file"
// ] ...
Or in C#:
// set 'logDir' to specific path like Environment.CurrentDirectory if you are on windows
.Target<File.Builder>(
"file",
file => file.Target.FileSystem(new FileSystem.DotNetFileSystem(logDir))
.Naming("{service}-{host}-{datetime}", "log").Done())
You can specify a number of deletion and rotation policies when configuring the file target. The deletion policies dictate when the oldest logs should be deleted, whilst the rotation policies dictates when the files should be rotated (thereby the previous file archived).
Furthermore, you can specify a naming specification that dictates how the files should be named on disk.
The File target is a performance-optimised target. Logging always happens on a separate thread from the caller, so we try to reach a balance between throughput and latency on ACKs.
On Windows, overlapped IO is not used, because the files are opened in Append mode, should have equivalent performance. This means we should have similar performance on Linux and Windows.
The formatters used for the File target should be writing to TextWriter instances to avoid creating extra string copies in memory.
The file target is thought as a last-chance target, because by default, logs should be shipped from your nodes/machines to a central logging service. It can also be nicely put to use for local console apps that need to log to disk.
Note that disposing Logary, e.g. during application exit flushes all buffers.
I've been considering supporting NO_BUFFERING but this would require callers to possibly wait for the 4096 bytes buffer to fill up before ACKing messages. However, for low-throughput logging, where each log line may be around, say, 240 bytes of text, having the NO_BUFFERING flag set may end up losing us more than it gains us.
These runs illustrate the above points in a more direct manner. In all of these cases we're writing 10K events to disk.
inProcBuffer = false, flushToDisk = true, caller awaits all acks at the end
This is the safest option and takes 1.3 seconds to log, format and write 10K messages.
I 2016-11-08T11:04:00.6125063+00:00: Event 1 [Logary.Samples.main]
number => 1
...
[12:04:02 DBG] Flushing to disk.
...
I 2016-11-08T11:04:02.0201345+00:00: Event 9402 [Logary.Samples.main]
number => 9402
[12:04:02 DBG] Flushing to disk.
I 2016-11-08T11:04:02.0201345+00:00: Event 9403 [Logary.Samples.main]
number => 9403
I 2016-11-08T11:04:02.0201345+00:00: Event 9404 [Logary.Samples.main]
number => 9404
...
I 2016-11-08T11:04:02.0891350+00:00: Event 10000 [Logary.Samples.main]
number => 10000
[12:04:02 DBG] Flushing to disk.
...
The interleaved flushes shows the batching functionality of the File target in action.
inProcBuffer = false, flushToDisk = true, caller awaits all ack after each
This example represents the worst-case usage of the safest configuration.
I 2016-11-08T11:14:42.9071732+00:00: Event 1 [Logary.Samples.main]
number => 1
[12:14:42 DBG] Flushing to disk.
I 2016-11-08T11:14:42.9711735+00:00: Event 2 [Logary.Samples.main]
number => 2
[12:14:42 DBG] Flushing to disk.
I 2016-11-08T11:04:02.0201345+00:00: Event 9403 [Logary.Samples.main]
number => 3
[12:14:42 DBG] Flushing to disk.
I 2016-11-08T11:04:02.0201345+00:00: Event 9404 [Logary.Samples.main]
number => 4
[12:14:42 DBG] Flushing to disk.
...
I 2016-11-08T11:15:04.7635448+00:00: Event 10000 [Logary.Samples.main]
number => 10000
[12:15:04 DBG] Flushing to disk.
With this configuration, the File target would still batch other threads' Messages but since this example has a single thread producer, there's only a single Message available for the target every loop.
inProcBuffer = true, flushToDisk = false, writeThrough=false caller awaits all acks at the end
This is the least safe and most speedy option. Useful when you're shipping logs away from the node and configure those shippers in a safer manner. In this case, .Net and the operating system and the device drivers decide when to flush.
On exit/dispose of Logary, all targets are always flushed.
[12:32:05 INF] Event 1
...
[12:32:06 INF] Event 10000
[12:32:48 DBG] Shutting down Logary.
...
[12:32:48 DBG] Flushing to disk.
In this example, the actual time taken is dominated by the time to generate the messages.
Development has been sponsored by Tradera.com.
Logary also includes a logging target for Google Cloud Stackdriver.
The target can be configured like so:
open Logary.Targets.Stackdriver
let projectId = "your gcloud project id"
// either a custom name, or you can use one of the well-known stream names that you can retrieve from [the lists](https://cloud.google.com/logging/docs/view/logs_index)
// this name doesn't have to be url-encoded as per the spec, the target will do that for you
// the specified log should exist before use
let logname = "the stream you want to log to"
// create your monitored resource:
let resource = ComputeInstance("my zone", "my instanceId")
// or container:
// let resource = Container("my cluster", "my namespace", "my instanceID", "my pod", "my name", "my zone")
// or appengine:
// let resource = AppEngine("my moduleId", "my version")
let conf = StackdriverConf.create(projectId, logname, resource)
Then, within withTargets:
Stackdriver.create conf "target-name"
add ambientSpanId middleware to the target, if you want to use ambient span
jaegerTargetConf |> TargetConf.middleware Middleware.ambientSpanId
then create span for some tracing, log message as usual:
use rootSpan = logger.buildSpan () |> Span.setMessage (eventX "root span") |> Span.start
do! eventX "before some action: {userId}" >> setField "userId" 123 |> logger.infoWithBP
// do some action : ...
do! eventX "after some action: {orderId}" >> setField "orderId" 321 |> logger.infoWithBP
let conStr = "Host=;Database=;Username=;Password=;"
use childSpan = Span.create logger |> Span.setMessage (eventX "child span" >> tag "DB Query" >> tag "Postgresql" >> setContext "conn str" conStr) |> Span.start
let sql = "select count(*) from xxx"
do! eventX "query : {sql}" >> setField "sql" sql >> setTimestamp (Instant.FromUnixTimeSeconds 1L) |> logger.infoWithBP
if not using ambient span, you can use Message.setSpanId for log message and Span.setParentSpanInfo for childSpan creation.
do! eventX "after some action: {orderId}" >> setField "orderId" 321 >> setSpanId rootSpan.info.spanId |> logger.infoWithBP
// use explicitly setParentSpanInfo style, since we use hopac `do! timeOutMillis 100` before (the ambientSpanId middleware will not be guaranteed)
let childSpan = Span.create logger |> Span.setMessage (eventX "child span" >> tag "DB Query" >> tag "Postgresql" >> setContext "conn str" conStr) |> Span.setParentSpanInfo rootSpan.info |> Span.start
LogaryFactory.New("demoService",
conf => conf
.InternalLoggingLevel(LogLevel.Verbose)
.Target<Debugger.Builder>("internal.debugger", tb => tb.UseForInternalLog())
.Target<Logary.Targets.Console.Builder>("internal.console", tb => tb.UseForInternalLog())
.Target<LiterateConsole.Builder>("console1")
.Target<AliYun.Builder>("AliYunLog", tb => {
tb.MinLevel(LogLevel.Verbose)
.Target
.ConfClient("key",
"keyid",
"endpoint")
.ConfLogLocation("project", "logstore")
.SetConnectTimeOut(1000)
.SetReadWriteTimeOut(5000)
.Done();
})
);
Target for Microsoft Azure AppInsights logs the events as TRACE-messages (or Events/Metrics with a different MappingConfiguration). You need to set the API-key first. Then when you go to Azure Portal Application Insights and Overview -> Search you should be able to find the targets from there. Metrics goes to Metrics Explorer -> Add Chart -> Custom. More info...
Logary is a production-grade logging and metrics library. We've also built targets that integrate with external paid services. These are listed here.
Learn how people use your app with the world's most advanced mobile & web analytics.
[Purchase today](mailto:henrik@haf.se?subject=Logary Mixpanel Target)
We like open source – so in the purchase the reference source is provided so that it can be debugged like the rest of Logary.
Send an e-mail to purchase
This assumes you have an account at Mixpanel.
You can't rely on any one notification method for critical alerts. Get alert notifications via iOS & Android push, SMS, and phone calls; escalate automatically to team members if the alert is not acknowledged.
The Logary target for OpsGenie ensures that you can bring in your Logging and Metrics into your daily operations.
This assumes you have an account at OpsGenie.
source https://www.nuget.org/api/v2
nuget Logary.Targets.Elmah.Io
OR:
Install-Package Logary.Targets.Elmah.Io
Configure elmah.io just like you would any normal target.
#if INTERACTIVE
#I "bin/Release"
#r "Hopac.Core.dll"
#r "Hopac.dll"
#r "NodaTime.dll"
#r "Logary.dll"
#r "Logary.Riemann.dll"
#endif
open System
open NodaTime
open Hopac
open Logary
open Logary.Configuration
open Logary.EventProcessing
open Logary.Targets
open Logary.Targets.ElmahIO
open System.Threading
[<EntryPoint>]
let main argv =
use mre = new ManualResetEventSlim(false)
use sub = Console.CancelKeyPress.Subscribe (fun _ -> mre.Set())
let logary =
let elmahioConf =
{ logId = Guid.Parse(Environment.GetEnvironmentVariable("ELMAH_IO_LOG_ID"))
apiKey = "api key form elmah io"}
Config.create "Logary.ElmahIO" "localhost"
|> Config.targets [
Console.create Console.empty "console"
ElmahIO.create elmahioConf "elmah.io"
]
|> Config.processing (Events.events |> Events.sink ["console";"elmah.io";])
|> Config.build
|> run
let logger =
logary.getLogger (PointName [| "Logary"; "Samples"; "main" |])
Message.eventFormat("{userName} logged in", [| "haf" |])
|> Logger.logSimple logger
Message.eventFormat (Info, "{userName} logged in", [| "adam" |])
|> Logger.logSimple logger
mre.Wait()
0
Or from C#:
// ...
.Target<ElmahIO.Builder>(
"elmah.io",
conf => conf.Target.WithLogId("GUID_HERE"))
You'll get the same view by logging this Message:
type Tenant =
{ tenantId : string
permissions : string }
let exnMsg =
Message.event Error "Unhandled exception"
|> Message.setSimpleName "A.B.C"
|> Message.setFieldFromObject "tenant" { tenantId = "12345"; permissions = "RWX" }
|> Message.setContextFromMap (Map
[ "user", box (Map
[ "name", box "haf"
"id", box "deadbeef234567"
])
])
|> withException Message.addExn
This assumes you have an account at elmah.io.
SumoLogic is a hosted service (at about 99 USD per month) that unifies logging, metrics, analytics and dashboards in a single service. As such it's a perfect Target for Logary, since Logary supports both logs and metrics.
Have a look at @neoeinstein's Logary.Targets.SumoLogic for the official docs and a sample of how to use it.
source https://www.nuget.org/api/v2Absolutely! You have two options;
This is by far the easiest option and ensures that your Target is stable and easy to use for your customers. I'll even write some Markdown/HTML-formatted docs for your site about how to use Logary with your target.