1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Core
.Logging
.Tests
18 using System
.Diagnostics
;
19 using System
.Security
.Principal
;
20 using NUnit
.Framework
;
23 public class DiagnosticsLoggerTestCase
29 if (EventLog
.Exists("castle_testlog"))
31 EventLog
.Delete("castle_testlog");
35 private void AssertAdmin()
37 WindowsPrincipal windowsPrincipal
= new WindowsPrincipal(WindowsIdentity
.GetCurrent());
38 if(windowsPrincipal
.IsInRole(WindowsBuiltInRole
.Administrator
)==false)
40 Assert
.Ignore("This test case only valid when running as admin");
45 public void SimpleUsage()
47 DiagnosticsLogger logger
= new DiagnosticsLogger("castle_testlog", "test_source");
49 logger
.Warn("my message");
50 logger
.Error("my other message", new Exception("Bad, bad exception"));
52 EventLog log
= new EventLog();
53 log
.Log
= "castle_testlog";
54 log
.MachineName
= ".";
56 Assert
.AreEqual(2, log
.Entries
.Count
);