Skip to content

Instantly share code, notes, and snippets.

@DmitriyVlasov
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DmitriyVlasov/bd214e8b3f7fd23225e5 to your computer and use it in GitHub Desktop.
Save DmitriyVlasov/bd214e8b3f7fd23225e5 to your computer and use it in GitHub Desktop.
Пример работы с логом событий на F#
open System.Diagnostics
let sizeEventLog (el : EventLog) =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey( @"System\CurrentControlSet\Services\EventLog\" + el.Log )
|> Option.ofNull
|> Option.bind ( fun registryKey -> registryKey.GetValue("FIle") |> Some )
|> Option.bind Option.ofNull
|> Option.bind ( fun x -> x.ToString() |> Some )
|> Option.bind ( fun filePath -> new FileInfo(filePath) |> Some )
|> Option.bind ( fun fi -> fi.Name |> Some )
|> Option.fill ""
let showOverflowAction (el:EventLog) =
match el.OverflowAction with
| OverflowAction.OverwriteOlder -> sprintf "Записи сохраняются минимум %d дней." el.MinimumRetentionDays
| OverflowAction.DoNotOverwrite -> "Более старые записи не перезаписываются."
| OverflowAction.OverwriteAsNeeded -> "Перезаписывать более старые записи."
| _ -> ""
printfn "| %-25s | %-25s | %13s | %-10s | %-10s | %s " "Имя журнала" "Описание" "Записей, шт" "Max, kB" "Size, kB" "Обработка переполнения"
printfn "%s" ( String.init 130 (fun _ -> "-") )
EventLog.GetEventLogs()
|> Array.map (fun el ->
sprintf "| %-25s | %-25s | %13d | %-10d | %-10A | %s"
el.Log el.LogDisplayName el.Entries.Count el.MaximumKilobytes (sizeEventLog el) (showOverflowAction el) )
|> Array.iter ( printfn "%s" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment