Last active
August 29, 2015 14:22
-
-
Save DmitriyVlasov/bd214e8b3f7fd23225e5 to your computer and use it in GitHub Desktop.
Пример работы с логом событий на F#
This file contains 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
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